- 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 03:44 AM
can I know how to create system property with json string
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-04-2023 03:57 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-04-2023 03:47 AM
You can do 1 thing ...
instead of manually writing the JSON, you can compile CSV file with 2 fields: Location, Group
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-04-2023 03:40 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-04-2023 02:52 AM
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.