How should a third part app update existing Request Item variables via API?

Jeff316
Kilo Guru

We have catalog items that generate REQ and Request Items in ServiceNow. We have a homemade third party app that knows the RITM number and needs to update variables on the RITM in ServiceNow from the home made application. Is there some oob API they can reference to POST updates to the variables of the RITM? What is the best way to have them update variables?

1 ACCEPTED SOLUTION

Ashutosh Munot1
Kilo Patron
Kilo Patron

HI,

Sorry for Delayed Response:

 

Follow below process:

1) Create Scripted Rest API put PUT method.

2) Give them one Predefined JSON format in which you want data from them, which will have your ritm number as well..

3) So you will have to parse this RITM number in Scripted REST API and then glide record this RITM and update the variables.


See below script:

var obj = '';
obj = request.queryParams.number; // This is our Query param for Finding RITM in System, You will have number

var state='';
var status='';

var reqbody = request.body;
var reqdata = reqbody.data;

if(obj && obj!=''){

var inc = new GlideRecord('sc_req_item');
inc.addQuery('number',obj);
inc.query();
if(inc.next()){
inc.variables.variable_name = reqdata.parameter;//Parameter means the key in JSON
status = 'success';
}


THanks,
Ashutosh

View solution in original post

12 REPLIES 12

Thanks Ashu bro.. 🙂

hi Ashutosh, thanks for this. Tried running it but it's not saving the value even in work notes

(function process( /*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
    var pathParams = request.pathParams;
    var obj = pathParams.number; // [false] 

    var body = request.body.data;

    if (obj && obj != '') {
        var ritm = new GlideRecord('sc_req_item');
        //         ritm.addQuery('number', obj);
        ritm.addQuery('sys_id', obj);
        ritm.query();
        if (ritm.next()) {
            ritm.variables.u_name = body.variables.mgmt;
            ritm.work_notes = "owrk"; //Parameter means the key in JSON
        }
    }
//     return {
//         "id": obj,
//         "var": ritm.variables.u_name,
//         "note": ritm.work_notes,
//         "a": ritm.short_description,
//         "test": ritm.variables.u_activity


//     };

})(request, response);

Mason Adams
Tera Contributor
PUT https://{instance}.service-now.com/api/sn_sc/servicecatalog/variables/{table_name}/{sys_id}
table name can what ever task you want to reference and sys_id is that task's sys_id 
pass the variables in the body
{"var1":"val1","var2":"val2"}