- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-04-2023 02:29 AM
I have to write script to get assigned the assignment group based on user location.if the user is based on beijing location,the beijing assignment group should get auto populated in the assignment group.I'm having so many users from different locations and having different assignment group.how to wirte the script,anyone help me.the field names are location and assignment group from form.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-04-2023 02:52 AM
create a system property which will hold json string
then in your workflow get the value of that property.
then get user's location
then parse the JSON and get the group for this location and set it
Example:
[
{
"location": "Beijing",
"group": "Group 1 SysId"
},
{
"location": "India",
"group": "Group 2 SysId"
}
]
Workflow run script
var userLocation = ''; // get the user's location based on your logic
var parsedData = JSON.parse(gs.getProperty('propertyName'));
var group;
for(var i=0;i<parsedData.length;i++){
if(parsedData[i].location == userLocation){
group = parsedData[i].group;
break;
}
}
current.groupField = group;
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-04-2023 02:52 AM
create a system property which will hold json string
then in your workflow get the value of that property.
then get user's location
then parse the JSON and get the group for this location and set it
Example:
[
{
"location": "Beijing",
"group": "Group 1 SysId"
},
{
"location": "India",
"group": "Group 2 SysId"
}
]
Workflow run script
var userLocation = ''; // get the user's location based on your logic
var parsedData = JSON.parse(gs.getProperty('propertyName'));
var group;
for(var i=0;i<parsedData.length;i++){
if(parsedData[i].location == userLocation){
group = parsedData[i].group;
break;
}
}
current.groupField = group;
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-04-2023 03:39 AM
There are a lot of locations from users at least 160.so in system property i have to write the whole details right?cant we dynamically write the script in the catalog task workflow only to fetch the location by searching and fetch the related assignment group of that nearest location and assign to the user location assignment group
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-04-2023 03:41 AM
if no location found for the user location it has to go to service desk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-04-2023 03:42 AM
in workflow run script you will have to use multiple if else conditions.
what if in future a new location and new group gets added? you need to make script changes.
what if in future same location gets associated to different group. you will have to make script changes.
if you handle it via property it will be one time job and no workflow script change will be required in future.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader