set assignment group based on user location by using workflow

sainath reddy
Tera Contributor

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.

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@sainath reddy 

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.

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

View solution in original post

11 REPLIES 11

Ankur Bawiskar
Tera Patron
Tera Patron

@sainath reddy 

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.

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

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

if no location found for the user location it has to go to service desk

 

@sainath reddy 

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.

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