API "sysparm_input_display_value" not working as advertised

Roger11
Giga Guru

I am trying to update the "business_service" field in the change_request record. This happily accepts a sys_id via an API call with JSON {"business_service":"sys_id_code"}. But if I try to populate using the Display Name of the field so that it looks up the sys_id and populates it by setting sysparm_input_display_value = true in the query parameters, the value in the JSON is inserted into the "value" field, not the "display value" field and the field remains blank on the change record.

"business_service": {
      "display_value": "",
      "value": "A"

If I pass this data through using the Table API, it works fine. So is something broken in SN, or is there some way to call the Table API from within my API script and just pass the whole JSON blob through and wash my hands of it?
1 ACCEPTED SOLUTION

Roger11
Giga Guru

So, if there's no better way to do it and Table API is the only way to get to the sysparm_input_display_value functionality, I would say that the following code called from within a scripted API is the only option (where "mappingOutput" is either the body.data passed in from the original call, or a filtered set of data if you wish to lock down what Table API has access to but still need its richer functionality.

 var Createrequest = new sn_ws.RESTMessageV2();
var endpointurl = gs.getProperty('glide.servlet.uri') + 'api/now/table/change_request/'+sysId+'?sysparm_input_display_value=true';
Createrequest.setEndpoint(endpointurl);
Createrequest.setHttpMethod('PATCH');
Createrequest.setRequestHeader("authorization", header.authorization);
Createrequest.setRequestHeader("Accept", "application/json");
Createrequest.setRequestHeader('Content-Type', 'application/json');
Createrequest.setRequestBody(JSON.stringify(mappingOutput));
var Createresponse = Createrequest.execute();
output.http_status = (JSON.stringify(Createresponse.getStatusCode()));
output.status_message = Createresponse.getBody();
var operatemessage = JSON.parse(output.status_message);

View solution in original post

6 REPLIES 6

Ankur Bawiskar
Tera Patron
Tera Patron

Hi Roger,

It worked for me in table API.

Which API you are referring it is not working?

please share screenshot

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Table API works perfectly. But I am trying to build a custom PATCH API for normal change records (very similar to the OOTB SN Change Management normal change except that I want to call the API using the change number and not using the sys_id. (plus a bunch of other customisations later).

For some reason my corporate environment is not letting me cut/paste screenshots into this editor.

But the salient text parts of the REST API explorer are:

sysparm_input_display_value = true
 
Request Body
business_service = "A display value"
 
HTTP Method / URI
PATCH https://nabenterprisedev.service-now.com/api/xxxx/change/Normal/CHG000118727?sysparm_input_display_value=true
 

 
But in the response, the "A display value" is ending up in the "value" and leaving the "display value" part blank.
 
"business_service": {
"display_value": "",
"value": "A"
},
 
 
 
 

Roger11
Giga Guru

It appears that the sysparm_input_display_value ONLY applies to the TABLE API as described here ->  https://developer.servicenow.com/dev.do#!/reference/api/orlando/rest/c_TableAPI

 

Whereas I am using something similar to the Change Management API (here: https://developer.servicenow.com/dev.do#!/reference/api/orlando/rest/change-management-api#changemgm...)

 

So, is my best (or only) option to take the body.data and call the Table API (any examples on how to do this?) to apply the data, or build my own function that can detect if a field is a reference or not, and if it is to perform a search on the text value to return the sys_id of the value so the API call will be able to update that field?

Seems like a bit of a miss on SN's part.

 

Hi,

Since you want customization around this. Best approach would be to create a custom scripted rest api and allow the body as request

You can then use it for parsing and update the record and send customized response as well

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader