- 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:55 AM
Hi,
Do you have mappings [Location-> Assignment group] stored anywhere in your instance?
Thanks
Anil Lande

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-04-2023 02:59 AM
Create a new table to store the mapping between locations and assignment groups. This table should have two fields: Location and Assignment Group. Populate this table with the relevant mappings.
Populate the Assignment Group Mapping table:
- Populate the "Assignment Group Mapping" table with the appropriate mappings between locations and assignment groups. For each location, specify the corresponding assignment group.
Configure the workflow stages and activities:
- Add a new "Activity" to the workflow.
- Set the "Activity Type" to "Script".
- In the script, you will need to fetch the user's location and set the assignment group accordingly. Use the "current" variable to access the current record.
- Here's an example of a script that sets the assignment group based on the user's location (assuming you have a field named "location" on the User table):
// Get the user's location
var userLocation = current.user.location;
// Query the Assignment Group Mapping table
var assignmentGroupMapping = new GlideRecord('u_assignment_group_mapping');
assignmentGroupMapping.addQuery('location', userLocation);
assignmentGroupMapping.query();
// Set the assignment group based on the mapping
if (assignmentGroupMapping.next())
{
current.assignment_group = assignmentGroupMapping.assignment_group;
}