- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-06-2022 06:53 AM
Hi,
I have a requirement to create catalog tasks based on a list collector variable i.e Requested for. I was successfully able to auto-create the catalog task after submitting the request. I followed the below reference-https://community.servicenow.com/community?id=community_question&sys_id=8d970a7adb68ef04f7fca851ca96...
I have added the below code in my workflow run script activity:
var options = current.variables.requested_for;
var data = options.toString();
var data1 = data.split(",");
for (i=0; i < data1.length; i++) {
var sct = new GlideRecord('sc_task');
sct.initialize();
sct.short_description = 'iManage installation';
sct.description = 'Check if relevant software was installed to users device otherwise assist with physical implementation';
//sct.assignment_group = ??
sct.request_item = current.sys_id;
sct.insert();
}
There is a challenge in updating the assignment group as it should be updated based on requested for location.
The values can be hardcoded as an Eg: If the user location is London then the group should be XYZ, if the location is India then the assignment group should be ABC. There are around 5 static locations and their respective group is also allocated. I tried creating a custom field called location in group table and mapped the respective location for those groups. But I am not sure how the logic would fit in the above script.
Can you help me with the solution?
Solved! Go to Solution.
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-08-2022 11:50 PM
Hi,
you should have 1 more curly bracket to close the IF
var abc= new GlideRecord('sc_req_item');
abc.addQuery("sys_id", '73dfa9a1979301106952f8b3f153af92');
abc.query();
if(abc.next()){
var options = abc.variables.requested_for;
var data = options.toString();
var data1 = data.split(",");
for (i=0; i < data1.length; i++) {
var bbb = getAssignmentGroup(data1);
gs.print(bbb);
}
}
function getAssignmentGroup(user){
var groupSysId;
var gr = new GlideRecord("sys_user");
gr.addQuery("sys_id", user);
gr.query();
if (gr.next()) {
var country = gr.country;
switch(country.toString()){
case 'Brasil':
groupSysId = '15bcdbfc975301106952f8b3f153af58';
break;
case country == 'France':
groupSysId = 'fb57b129979301106952f8b3f153affd';
break;
default:
groupSysId = '679434f053231300e321ddeeff7b12d8'; // if user has no country info then use this group;
}
}
return groupSysId;
}
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-08-2022 11:44 PM
Hi
I am not sure what's wrong with the below code. As suggested I changed the value from data1[i] to data1, still facing the same issue:
Evaluator: com.glide.script.RhinoEcmaError: getAssignmentGroup is not a function. script : Line(10) column(0) 7: var data1 = data.split(","); 8: for (i=0; i < data1.length; i++) { 9: ==> 10: var bbb = getAssignmentGroup(data1); 11: gs.print(bbb); 12: 13: }
Below is my code:
var abc= new GlideRecord('sc_req_item');
abc.addQuery("sys_id", '73dfa9a1979301106952f8b3f153af92');
abc.query();
if(abc.next()){
var options = abc.variables.requested_for;
var data = options.toString();
var data1 = data.split(",");
for (i=0; i < data1.length; i++) {
var bbb = getAssignmentGroup(data1);
gs.print(bbb);
}
function getAssignmentGroup(user){
var groupSysId;
var gr = new GlideRecord("sys_user");
gr.addQuery("sys_id", user);
gr.query();
if (gr.next()) {
var country = gr.country;
switch(country.toString()){
case 'Brasil':
groupSysId = '15bcdbfc975301106952f8b3f153af58';
break;
case country == 'France':
groupSysId = 'fb57b129979301106952f8b3f153affd';
break;
default:
groupSysId = '679434f053231300e321ddeeff7b12d8'; // if user has no country info then use this group;
}
}
return groupSysId;
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-08-2022 11:50 PM
Hi,
you should have 1 more curly bracket to close the IF
var abc= new GlideRecord('sc_req_item');
abc.addQuery("sys_id", '73dfa9a1979301106952f8b3f153af92');
abc.query();
if(abc.next()){
var options = abc.variables.requested_for;
var data = options.toString();
var data1 = data.split(",");
for (i=0; i < data1.length; i++) {
var bbb = getAssignmentGroup(data1);
gs.print(bbb);
}
}
function getAssignmentGroup(user){
var groupSysId;
var gr = new GlideRecord("sys_user");
gr.addQuery("sys_id", user);
gr.query();
if (gr.next()) {
var country = gr.country;
switch(country.toString()){
case 'Brasil':
groupSysId = '15bcdbfc975301106952f8b3f153af58';
break;
case country == 'France':
groupSysId = 'fb57b129979301106952f8b3f153affd';
break;
default:
groupSysId = '679434f053231300e321ddeeff7b12d8'; // if user has no country info then use this group;
}
}
return groupSysId;
}
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-09-2022 12:06 AM
Thanks,
Modified a few other things as well!!
var abc= new GlideRecord('sc_req_item');
abc.addQuery("sys_id", '73dfa9a1979301106952f8b3f153af92');
abc.query();
while(abc.next()){
var options = abc.variables.requested_for;
var data = options.toString();
var data1 = data.split(",");
for (i=0; i < data1.length; i++) {
var bbb = getAssignmentGroup(data1[i]);
gs.print(bbb);
}
}
function getAssignmentGroup(user){
var groupSysId;
var gr = new GlideRecord("sys_user");
gr.addQuery("sys_id", user);
gr.query();
while(gr.next()) {
var country = gr.location.getDisplayValue();
switch(country.toString()){
case 'Brasil':
groupSysId = '15bcdbfc975301106952f8b3f153af58';
break;
case country == 'France':
groupSysId = 'fb57b129979301106952f8b3f153affd';
break;
default:
groupSysId = '679434f053231300e321ddeeff7b12d8'; // if user has no country info then use this group;
}
}
return groupSysId;
}