Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Script for Catalog Task routed to particular assignment team

Jagadish10
Mega Expert

Hello Team,

I have a catalog item created. In the item description, I have created a workflow and attached to this particular catalog item.

Now, In the workflow, I have written a script to assign the task to particular assignment group based on the region populated on the task form.

Please note: Field 'Region' is one of the field on the task form.

Below is the code I have written, I'm not able to track the error in the code. Please help.

var America = US;

var reqForReg = current.request.u_region;

if(reqForReg==America)

{

task.assignment_group = 'Global Communications';

}

else {

task.assignment_group = 'Regional Communications';

}

Thanks

Jagadish

1 ACCEPTED SOLUTION

Hi Ashutosh,



I did go through the logs to find the bug, so that I can fix it. But it was difficult to read the logs and trace the error at right place.


So, I used the getDisplayValue() to avoid conflicts and it worked for me



I had to fumble as I'm new to writing scripts.



var america='US';


var region = current.task.u_region.getDisplayValue();


if (america==region) {


      task.assignment_group.setDisplayValue('Global Communications');


}


else {


  task.assignment_group.setDisplayValue('Regional Communications');


}



Thanks


Jagadish


View solution in original post

7 REPLIES 7

Gaurav Bajaj
Mega Sage

Hi Jagdish,



Region field is on the sc_task table or sc_request table because as per your script, it looks to be on request table.


Please make sure you are referencing the right table.



var reqForReg = current.request.u_region;




Thanks


Gaurav


Hi Gaurav,



Thanks for the reply.


I'm pointing to the task table and made the required change.



Even then, the script is not working. I also used 'US' single quotes as suggested by @Ashutosh Munot but nothing worked so far.



Are you seeing any other bug in my code ?



Script:



var America = 'US' ;


var reqForReg = current.task.u_region;


if(reqForReg==America)


{


task.assignment_group = 'Global Communications';


}


else {


task.assignment_group = 'Regional Communications';


}



Please note that both Global Communications and Regional Communications already exists in my groups list.



Thanks


Jagadish


Hi Jagadish,



var America = 'US' ;


var reqForReg = current.task.u_region; // Also which type of field this is? Choice or reference and what value comes in this check as per below:


gs.log(reqForReg);


if(reqForReg==America)


{


task.assignment_group = 'As assignment group is reference field, here it should be sys id of group';


}


else {


task.assignment_group = 'As assignment group is reference field, here it should be sys id of group';


}



Thanks,



Please mark Helpful or Correct


Hi Ashutosh,



I did go through the logs to find the bug, so that I can fix it. But it was difficult to read the logs and trace the error at right place.


So, I used the getDisplayValue() to avoid conflicts and it worked for me



I had to fumble as I'm new to writing scripts.



var america='US';


var region = current.task.u_region.getDisplayValue();


if (america==region) {


      task.assignment_group.setDisplayValue('Global Communications');


}


else {


  task.assignment_group.setDisplayValue('Regional Communications');


}



Thanks


Jagadish