How to create a standard change request via API with display values instead of reference field values?

Sandeep Singh1
Kilo Contributor

I am able create a standard change with:

POST https://<org-sub-domain>.service-now.com/api/sn_chg_rest/change/standard/{standard_change_template_id}

However, I have to pass reference field values to get the request created with appropriate display value. Example:

For a field assigned_to I have to pass value like: 416e07f00f571700b322807be1050efb to make it display my name.

Is there a way to pass the display values directly? If not, what's the best way to get display value for a reference field?

1 ACCEPTED SOLUTION

Brad Bowman
Kilo Patron
Kilo Patron

It may be about the same - or a difference of where you want the work to be done, but an alternative is to pass in 'John Smith' and have the script on the Scripted REST Resource parse that and query the table to use the sys_id when the change record is created.

View solution in original post

5 REPLIES 5

Brad Bowman
Kilo Patron
Kilo Patron

Whenever you populate a reference field, you need to supply the sys_id, since that is the value stored in that field on the db.  I'm not clear on your next question - do you need to know how to lookup the sys_id when you have a name/display value?

Sandeep Singh1
Kilo Contributor

Yes, I am looking for a way to get the sys_id by display value for a given field. Example: I want to pass the display value John Smith for assigned_to field and want to get the sys_id for John Smith i.e. 416e07f00f571700b322807be1050efb so that I can then create the standard change request using that value for assigned_to field.

Sandeep Singh1
Kilo Contributor

At this moment, I think the only way is to first fetch all sys_ids for each field from db table by making a GET call to respective table:

GET /now/table/{tableName}
 
Then, once I have all the values, I will make a POST call to /api/sn_chg_rest/change/standard/{standard_change_template_id}
 
I am just wondering if there's a better alternate than that.

Brad Bowman
Kilo Patron
Kilo Patron

It may be about the same - or a difference of where you want the work to be done, but an alternative is to pass in 'John Smith' and have the script on the Scripted REST Resource parse that and query the table to use the sys_id when the change record is created.