Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

flow designer script the assignment group based on a catalog variable chosen

Not applicable

for 'Create Catalog Task' action in my flow, I have scripted the Assignment Group as one that has a name that starts with 'CLD - Saas' and contains the name of the product variable: 

var ag = fd_data.trigger.current.assignment_group;
var product = fd_data.trigger.current.variables.product;

var group = new GlideRecord('sys_user_group'); 
group.addEncodedQuery('nameSTARTSWITHCLD - SaaS^nameLIKE' + product); 
group.query(); 
if (group.next()) { 
    ag = group;
}
return ag;

but when I try to activate the flow it gives me an error about not being able to use 'current'. 

What am I doing wrong? 

13 REPLIES 13

Hi @Ankur Bawiskar,

I just tried to adapt your script for my needs but receiving the message 
Error: "ag" is not defined.,Detail: "ag" is not defined.
when executing.

var ritmSysId = fd_data.trigger.request_item.sys_id;
var rec = new GlideRecord('sc_req_item');
rec.get(ritmSysId);

var product = rec.variables.region;

var group = new GlideRecord('sys_user_group');
group.addEncodedQuery('nameSTARTSWITHIntune Keyuser ' + product);
group.query();
if (group.next()) {
    ag = group.getUniqueValue();
}
return ag;

Any idea on this?

Thanks in advance!

Kevin

Hi,

your encoded query seems wrong

group.addEncodedQuery('nameSTARTSWITHIntune Keyuser ' + product);

Ensure you use correct query to search

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

Thanks for the advice!

group.addEncodedQuery('nameSTARTSWITHIntune Keyuser^nameLIKE' + product.getDisplayValue());
 
solved the issue.

@Kevin Lübben 

Glad to help.

Please mark response helpful as well.

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

shloke04
Kilo Patron

Hi,

Simply update your script as below and should work:

var ag;
var product = fd_data.trigger.current.variables.product;

var group = new GlideRecord('sys_user_group'); 
group.addEncodedQuery('nameSTARTSWITHCLD - SaaS^nameLIKE' + product); 
group.query(); 
if (group.next()) { 
    ag = group.sys_id;
gs.info('Value of Group is ' + ag);
}
return ag;

In case if it still does not works, check what is coming in Log Statement which I have given above.

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

 

Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke