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

can I know how to create system property with json string

Go to sys_properties.LIST, then click New

Enter the JSON in the Value field


Please mark this post as a solution and also as helpful, if this resolves your issue or query.

Thanks,
Subhadeep Ghosh.

You can do 1 thing ...

instead of manually writing the JSON, you can compile CSV file with 2 fields: LocationGroup

Then using online conversion tools, you can convert this CSV into JSON (e.g. from https://www.site24x7.com/tools/csv-to-json.html)

Please note that @Ankur Bawiskar 's solution is much easier solution, than writing more than 200 lines of code in the workflow script for 160 locations.


Please mark this post as a solution and also as helpful, if this resolves your issue or query.

Thanks,
Subhadeep Ghosh.

Wow @Ankur Bawiskar , 

Didn't know about JSON within system property - I'll definitely try this out.

This was a new learning for me, same methodology can be used for many other requirements.

 


Please mark this post as a solution and also as helpful, if this resolves your issue or query.

Thanks,
Subhadeep Ghosh.

subhadeep1618
Tera Guru

Hi @sainath reddy ,

Where do you have this requirement?

In any service catalog workflow or any console form (like change request, incident, etc.) ?

Please share your requirement flow, so that I can guide you accordingly.


Please mark this post as a solution and also as helpful, if this resolves your issue or query.

Thanks,
Subhadeep Ghosh.