- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-10-2020 11:23 PM
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?
Solved! Go to Solution.
- Labels:
-
Integrations
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-14-2020 04:31 PM
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);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-11-2020 04:06 PM
Try to think of people who come and look at this question. They will have the same problem with me. Do we have enough information here that they don't need to go looking elsewhere? Not yet they don't. I'm here because this question just agreed that he had to accept that's the way it is.
So, either this question needs to identify why sysparm_input_display_value only works on the table API and how to achieve being able to pass display values into non-table api's or substantially provides useful direction to others.
I'm thinking setting the sysparm_input_display_value should happen and that my API will need to catch that parm if set to true and then forward the body data to a table API call - I have seen one script that does this, but cannot find it now. I've been stumbling around for a day trying to figure out how to call the table API from within my script - any help here?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-14-2020 04:31 PM
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);