Flow Designer

kirankr2061
Tera Contributor

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.

kirankr2061_0-1750228067858.png

No scripting available for Approval activity 

kirankr2061_1-1750228116596.png

To the owners string field, I need to send approval

How can I achieve this?

2 ACCEPTED SOLUTIONS

anshul_goyal
Kilo Sage

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

View solution in original post

Roshnee Dash
Tera Guru

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

  1. Trigger: Catalog item submitted.
  2. Script Step: Extract email and query sys_user.
  3. Approval Step: Use approver_sys_id from script output.

 

Your feedback makes the community stronger! If you found this helpful, marking it as the correct answer helps others.
Stay awesome,
Roshnee Dash

View solution in original post

7 REPLIES 7

Roshnee Dash
Tera Guru

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

  1. Trigger: Catalog item submitted.
  2. Script Step: Extract email and query sys_user.
  3. Approval Step: Use approver_sys_id from script output.

 

Your feedback makes the community stronger! If you found this helpful, marking it as the correct answer helps others.
Stay awesome,
Roshnee Dash

The script you mentioned is it an action? what is the name of that action 

Hi @kirankr2061 
You need to create a custom action for this.

Your feedback makes the community stronger! If you found this helpful, marking it as the correct answer helps others.
Stay awesome,
Roshnee Dash