Flow designer script

Bharathkumar33
Giga Contributor

I am trying to create a flow in flow designer where based on the users region, a particular assignment group has to be auto populated. Below is the script I have written in the assignment group toggle script field.

var userId = fd_data._1__get_catalog_variables.requested_for.toString();

var usr = new GlideRecord('sys_user');

if (usr.get(userId)) {
var loc = usr.getValue('u_region');

if (loc == 'sysid') {
return 'assignment group 1 sysid';
}
else if (loc == 'sysid') { 
return 'assignment group 2 sys id';
}
else if (loc == 'sysid') {
return 'assignment group 3 sysid';
}
else
return 'assignment group 4 sys id';
}
}

However I am getting empty value in the assignment group field. Can someone please help me.

3 REPLIES 3

pavani_paluri
Tera Guru

Hi @Bharathkumar33 ,

 

When you mention sysid in each of your if conditions, those should actually be the sys_ids of the region records you’re checking against. Each if block must compare against the correct region sys_id, not the same placeholder string. Please update your script so that each condition uses the actual region sys_id values.

If you’re still facing issues after that, paste the exact script you’re currently using (with the real sys_ids included) so I can review it and advise the next steps.

 

if (loc == ' Apac_sysid') {
return 'assignment group 1 sysid';
}
else if (loc == 'EMEA_sysid') { 
return 'assignment group 2 sys id';
}
else if (loc == 'AMER_sysid') {
return 'assignment group 3 sysid';
}
else { 
return 'assignment group';

}

 

Mark it helpful if this helps you to understand. Accept solution if this give you the answer you're looking for
Kind Regards,
Pavani P

 

 

 

GlideFather
Tera Patron

Ahoy @Bharathkumar33,

 

have you tried to log what you get or see the test flow executions?

 

Also, there's "flow variable" that can be created and its result can be used as a data pill if I remember correctly.

GlideFather_0-1778782021094.png

 

 

or you can try different approach in, try to add logs to see what is returned from this

var userId = fd_data._1__get_catalog_variables.requested_for.toString();

 and eventually try to adjust this, to. something else, for example:

var userId = fd_data._1__get_catalog_variables.requested_for;

//or

var userId = fd_data._1__get_catalog_variables.requested_for.sys_id;

 

Also, is there any chance that the requested_for would be empty?

 

If you do some changes in flow, you can press the Test button to reuse existing record, no need to create new and new test submissions.

 

Let me know what you found

_____
Answers generated by GlideFather. Check for accuracy.

Tanushree Maiti
Mega Patron

Hi @Bharathkumar33 ,

 

Try this one,

 

var userId = fd_data._1__get_catalog_variables.requested_for.toString(); // Ensure underscores are correct
var usr = new GlideRecord('sys_user');
if (usr.get(userId))
 {
    var loc = usr.getValue('u_region');
    switch (loc) 
{
        case 'REGION_1_SYSID':
            return 'GROUP_1_SYSID';
        case 'REGION_2_SYSID':
            return 'GROUP_2_SYSID';
        case 'REGION_3_SYSID':
            return 'GROUP_3_SYSID';
        default:
            return 'DEFAULT_GROUP_SYSID';
    }
Please mark this response as Helpful & Accept it as solution if it assisted you with your question.
Regards
Tanushree Maiti
ServiceNow Technical Architect
Linkedin: