Flow designer inline script to update an integer field with the sum of two other choice fields
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
5 hours ago
Hi, I really want to use a flow to set a field value. I could probably get this working easily as a business rule but at this point it's the principal of the thing. I have 2 choice fields with numeric values that, when updated, should be summed together and that result used to update an integer field. In the flow record I've plugged the script into an update record action using the following settings:
and my script content below:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
29m ago
The script field on actions has sample text to guide you in the expected/accepted values that you can use in the script, and how to update the field value, so you can't just make up a different convention like 'inputs' and 'outputs', with random GlideRecord methods like getValue, setValue and update.
Using 3 out of box fields on the demand table - 2 choice fields with numeric values: priority + state, and an integer field: order, for example a successful script on an Update Record action would look like this:
/*
**Access Flow/Action data using the fd_data object. Script must return a value.
**Order number is offset by +1 in Error Handling Section.
**Available options display upon pressing "." after fd_data
**example: var shortDesc = fd_data.trigger.current.short_description;
**return shortDesc;
*/
// Get value of input fields and convert to integers
var benefit_value = fd_data.trigger.current.priority;
var effort_value = fd_data.trigger.current.state;
var benefit_number = parseInt(benefit_value, 10) || 0;
var effort_number = parseInt(effort_value, 10) || 0;
// Add values together
var score_value = benefit_number + effort_number;
// Set custom score and update record
return score_value;
