Group not populating on the request using Scripted REST API
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2025 02:19 AM
Hello all,
I am using Scripted REST API to create a catalog item request in service-now.
When I clicked on Explore Rest API in the related links, and test, the request is getting created and the fields like,
short description and description are populating good but assignment group is not populating.
In the Scripte REST API, when I glide record the request table and passing the sys_id to the assignment group then the group is populating. But if I give the group name then it is not populating.
So, what changes can I do now.
Actually, in the RITM variables also, the Assignment group variable is not populating. We want to fix this.
Please help.
Here are the screen shots.
Regards,
Lucky
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2025 02:34 AM
are you getting sysId of group in your request?
If yes then your script to set variable and field should work fine
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
02-27-2025 03:00 AM
Hi @Lucky1 ,
I see you've put the log to check the assignmentgroup value.
is assignmentgroup is getting logged?
what are you expecting sysid or name of the group?
if it is sysid and your the request body contains the assignment group you don't have to make any changes.
if it is the name of the group that request body is containing you can set the group using setDisplayValue method
gr.assignment_group.setDisplayValue(assignmentgroup);
check the logs and make a decision
Please mark my answer as helpful/correct if it resolves your query.
Regards,
Chaitanya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2025 03:14 AM
hi @Lucky1
This issue typically arises because when you pass the name of the group instead of the sys_id, ServiceNow expects the sys_id to identify the correct record, especially for reference fields like Assignment Group.
you can modify your Scripted REST API code to retrieve the sys_id of the Assignment Group based on the name:
var assignmentGroupName = parsedData.assignment_group_CM; // assuming group name is passed
// Initialize a GlideRecord to fetch the sys_id of the Assignment Group
var groupGR = new GlideRecord('sys_user_group');
groupGR.addQuery('name', assignmentGroupName);
groupGR.query();
if (groupGR.next()) {
// Successfully found the group, now set the sys_id to the assignment_group field
var assignmentGroupSysId = groupGR.sys_id;
}
// YOU CAN USE THIS SYS_ID TO SET AS BELLOW
//cart.setVariable(item, “assignment_group_CM”, assignmentGroupSysId);
I hope my answer helps you to resolve your issue, if yes please mark my answer helpful and correct.
thank you
Rajesh