Third party User need to update the RITM(requested item) to service now instance using scripted web service.How i can achive this please help me out.

Nana5
Mega Guru

Third party User need to update the RITM(requested item) to service now instance using scripted web service.How i can achive this please help me out.

Example : suppose he want to update comment field so for that he will provide ritm number as a input. Based on the number need to get the field details from user and need to update to coresponding RITM.How can achive this please help me out.

Thanks

Prakash Ranjan

1 ACCEPTED SOLUTION

shloke04
Kilo Patron

Hi,



You need to Navigate to Scripted Rest Api's module and define a new Service say as Update RITM and fill in the Scripted Rest form. Once you save the form you need to define the Resources where you can define the required HTTP method say you can use "PUT" in your scenario to update and write a script as below:



Script:



(function process(/*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {


  var remote_number = request.u_number1;       Number coming as input from Source Application


  //gs.log('Remote Number is' + remote_number);


  var gr = new GlideRecord('sc_req_item');


  gr.addQuery('u_rest_request', remote_number);


  gr.query();


  if(gr.next()) {


  gr.short_description = request.short_description;


  gr.update();



return {'Status' : 'The Request created is:' + gr.u_rest_request};


  }


  else{


  return {'Status' : 'The request is not created'};


  }



})(request, response);




Hope this helps.mark the answer as correct/helpful based on impact.



Regards,


Shloke


Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

View solution in original post

21 REPLIES 21

shloke04
Kilo Patron

Hi,



You need to Navigate to Scripted Rest Api's module and define a new Service say as Update RITM and fill in the Scripted Rest form. Once you save the form you need to define the Resources where you can define the required HTTP method say you can use "PUT" in your scenario to update and write a script as below:



Script:



(function process(/*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {


  var remote_number = request.u_number1;       Number coming as input from Source Application


  //gs.log('Remote Number is' + remote_number);


  var gr = new GlideRecord('sc_req_item');


  gr.addQuery('u_rest_request', remote_number);


  gr.query();


  if(gr.next()) {


  gr.short_description = request.short_description;


  gr.update();



return {'Status' : 'The Request created is:' + gr.u_rest_request};


  }


  else{


  return {'Status' : 'The request is not created'};


  }



})(request, response);




Hope this helps.mark the answer as correct/helpful based on impact.



Regards,


Shloke


Hope this helps. Please mark the answer as correct/helpful based on impact.

Regards,
Shloke

Thanks !!!   Shloke.I will tried with this and update you.


HI Shloke,


  Thanks for you reply.can you please guide me how can i test this.Currently i am using postman chrome default tool to test the web service.Thanks in advance.



u_number1 what i can use for testing..




Thanks



Hi Shloke,


While doing the testing i am getting below respons.can you please help me out if m doing some mistake.



find_real_file.png


Thanks


Prakash