Custom Code to create Claim Number

can anyone help me out with the Custom Code and Format Data step to make my workflow get the “Record Id” add “MDF” to the front of it and put it in a new field?

I don’t know JavaScript yet and the AI is not helping me very well.

Hi @DHopcraft,

I would not use custom code for this but a calculation property: Create calculation and rollup properties

Best regards!

Thanks for the response. The out put I want is the letters MDF I front of the Record ID with no spaces. Calculations seem more for aggregation.

@DHopcraft I’m not sure what you’re referring to - the calculation property is providing that exact output, see the sample output at the bottom of the screen.

I’m fairly certain that - if you configure it as proposed - you’ll have exactly what you requested.

Sorry, first time posting and replied through my phone so I did not see the photo. Unfortunately the field I am trying to use is a Secondary Display Property and can’t be modified. I have been trying to avoid making additional fields to make this claim Number work but your suggestion seems the the most simple way to move forward. I will make a nother field and try it.

@DHopcraft if you don’t want a new property, the same could be achieved with a workflow and the “Edit record” workflow action. You can simply use that action to set the value of your already existing property to “MDF” followed by a token for record ID.

This was the solution that worked for the field! It took a bit to relaize that I needed to tick it to be available for the workflows! Thank you so much!

I have been trying to figure out the proper code for that for a week. I am in a Contact based Workflow that is triggered by a form submission that makes a record in a custom object. I need the workflow to get the Record Id from the new record in the custom object and put “MDF” in front of it into a new field (in the same object) called Claim Number but the adivice keeps changing and I honestly don’t know enough JavaScript to know exactly what is not working. HubSpot have just told me they can’t actually giveme any custom coding help.

exports.main = (event, callback) => {
try {
// Get the enrolled record’s ID
const recordId = event.object.objectId;

// Build MDF + Record ID
const claimNumber = `MDF${recordId}`;

// Expose it as an output for the workflow
callback({
outputFields: {
claim_number: claimNumber, // <-- workflow output name
},
});
} catch (error) {
callback({
error: error.message,
});
}
};

Do you mean like this?

@DHopcraft exactly :slightly_smiling_face:

Ok, I am going to set it live and give it a whirl!

That did not work :disappointed_face:

@DHopcraft what exactly didn’t work? How did you test? Can you share a screenshot of the entire workflow? I can help but I’ll need a lot more context.

Alternatively, I’d still recommend the calculation and if needed a sync property. Still the most robust solution.

@DHopcraft in your screenshot, you’re using a token for the record ID of a form submission it seems. Make sure to pick the right record ID.

I tested by submitting the form that triggers the workflow and subsquent record creation. After the record creation the flow wasmeant tocreat the claim number but there is nothing in the field. I will try your other suggestion.

@DHopcraft @can you please explain which objects are involved, which object the property should be on and which ID exactly it should pull?