How to set reference variables in Catalog API posts
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-14-2019 11:52 AM
HttpPost post = new HttpPost();
post.setURI(new URI("https://myinstance/api/sn_sc/servicecatalog/items/" + itemId +
"/add_to_cart"));
String encoding =
Base64.getEncoder().encodeToString(("User:Password").getBytes("UTF-
8"));
String authHeader = "Basic " + encoding;
post.setHeader(HttpHeaders.AUTHORIZATION, authHeader);
post.setHeader("Content-Type", "application/json");
/*WorkgroupAssignment is of type reference and never gets set.While
short_description' always gets set.*/
String data = "{'sysparm_quantity': 1,'variables': {'short_description':
'Example description','WorkgroupAssignment':'TSU-Middleware'};
StringEntity entity = new StringEntity(data);
/**
* *******************
* and now the body..
* *******************
*/
post.setEntity(entity);
WorkgroupAssignment is of type reference. Is there something special I have to do to set variables of type reference?
Thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-14-2019 12:10 PM
The value in a reference field/variable is actually the sys_id of the record being referenced, so I would try passing that instead of the display name of the group. Here is a doc on sys_ids: https://docs.servicenow.com/bundle/london-platform-administration/page/administer/table-administrati...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-14-2019 12:12 PM
Thanks...So in this case it would be the sys_id of the Workgroup (TSU-Middleware)...correct?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-14-2019 12:16 PM
If the variable is referencing the group [sys_user_group] table then it would be sys_id of the TSU-Middleware group on that table.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-14-2019 12:28 PM
Ok thanks...now I just have to figure out how I can get access to the sys_ids in that table.