- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-17-2025 11:29 PM
I am using flow designer for automating my process now I have a situation I am using reference catalog variable and dot walking through it and asking for approval, but the problem is in table all the email of users are stored in string fields and how can I do scripting for approval in flow designer so that I need to extract email and query it in sys_user table and send approvals.
No scripting available for Approval activity
To the owners string field, I need to send approval
How can I achieve this?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-18-2025 12:18 AM
Hello @kirankr2061,
Since Flow Designer's "Ask for Approval" action requires user references, but you're working with email addresses stored as strings, you'll need to convert those emails into user records dynamically. To do this, create a Custom Action that takes the owner string field as an input, processes the email addresses, queries the sys_user table, and pushes the valid user records into an array. Set this array as the output of your custom action. Then, place this custom action right before the "Ask for Approval" step in your flow, and use the output array from the custom action as the input for the approvers in the approval step.
Use below script in the custom action:
(function execute(inputs, outputs) {
var emails = inputs.emailString.split(','); // assume comma-separated
var approvers = [];
emails.forEach(function(email) {
email = email.trim();
var userGR = new GlideRecord('sys_user');
userGR.addQuery('email', email);
userGR.query();
if (userGR.next()) {
approvers.push(userGR.getUniqueValue()); // push sys_id
}
});
outputs.approverList = approvers; // return array of sys_ids
})(inputs, outputs);
Please mark my solution as helpful and accepted for future reference.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-18-2025 12:34 AM
To handle this scenario in ServiceNow Flow Designer, where you're using a reference catalog variable and need to dot-walk to extract an email stored as a string, then query the sys_user table to send approvals, you can follow this approach:
Use a Script Step to Query sys_user
You’ll need a Script step in Flow Designer to query the sys_user table using the email string.
Here’s a sample script you can use in the Script step:
(function execute(inputs, outputs) {
var email = inputs.email_string; // This should be the dot-walked email string
var userGR = new GlideRecord('sys_user');
userGR.addQuery('email', email);
userGR.query();
if (userGR.next()) {
outputs.approver_sys_id = userGR.getValue('sys_id');
} else {
outputs.approver_sys_id = ''; // Handle case where user is not found
}
})(inputs, outputs);
Inputs and Outputs
- Input: email_string — the email string from your catalog variable (dot-walked).
- Output: approver_sys_id — the sys_id of the user to be used in the approval action.
Use the Output in the Approval Action
In the Approval step, use the approver_sys_id from the script output as the Approver.
Example Flow Steps
- Trigger: Catalog item submitted.
- Script Step: Extract email and query sys_user.
- Approval Step: Use approver_sys_id from script output.
Stay awesome,
Roshnee Dash
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-18-2025 12:12 AM
Approvals are set to users or groups, so you need to query to the user/group table to find the correct ones.
If your field only contains string values, you will need to add a step before the approval step to get the email addresses from the owners field and use those to find the user records that you can then use in your approval step.
You can't create approval records for string values.
Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-18-2025 12:18 AM
Hello @kirankr2061,
Since Flow Designer's "Ask for Approval" action requires user references, but you're working with email addresses stored as strings, you'll need to convert those emails into user records dynamically. To do this, create a Custom Action that takes the owner string field as an input, processes the email addresses, queries the sys_user table, and pushes the valid user records into an array. Set this array as the output of your custom action. Then, place this custom action right before the "Ask for Approval" step in your flow, and use the output array from the custom action as the input for the approvers in the approval step.
Use below script in the custom action:
(function execute(inputs, outputs) {
var emails = inputs.emailString.split(','); // assume comma-separated
var approvers = [];
emails.forEach(function(email) {
email = email.trim();
var userGR = new GlideRecord('sys_user');
userGR.addQuery('email', email);
userGR.query();
if (userGR.next()) {
approvers.push(userGR.getUniqueValue()); // push sys_id
}
});
outputs.approverList = approvers; // return array of sys_ids
})(inputs, outputs);
Please mark my solution as helpful and accepted for future reference.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-18-2025 12:31 AM
you can use flow variable, query and store user/group sysId in that and then use that flow variable in Ask for Approval
also check this blog on how to use scripted approvals
Scripted Approvals in Flow Designer with Flow Variables
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-18-2025 02:17 AM
Thank you for marking my response as helpful.
As per new community feature you can mark multiple responses as correct.
If my response helped please mark it correct as well so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader