- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-15-2017 03:40 AM
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-15-2017 03:59 AM
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
Regards,
Shloke
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-16-2017 04:44 AM
Hi Prakash,
The code given by me was a sample code for Integrating between two Service Now instances. For postman chrome I have to check and then i can get back to you.
Regarding the error you are getting you can specify the Content as below:
"Content-Type - application/json OR application/xml depending on the format in which you want to send the Request/Response. The above content type mentioned in your screen shot is not supported by Service Now.
Regarding your first query for the use of u_number1 field, basically it checks for the Number coming as Request from Source Application, which I was using to check on the Target instance if the same number exists or not. if it exists I was trying to update the Record else insert it in the Target instance.
Hope this helps.mark the answer as correct/helpful based on impact.
Regards,
Shloke
Regards,
Shloke
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-16-2017 04:57 AM
Hi Shloke,
Thanks for reply.Please check and let me know.
btw i have change the content type to application/json but now lt as below:
{
"result": {
"Status": "The Request created is:undefined"
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-16-2017 05:02 AM
Can you give a log as " gs.log('Remote Number is' + remote_number);" after first line in the code to check what are you getting in the field remote_number, because based on that value only remaining code works and then you can debugg from there onwards.
Regards,
Shloke
Regards,
Shloke
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-16-2017 05:13 AM
Hi Shloke,
Its coming as undefined. so how i can get the number from another instance for testing puropse.
i am getting confuse here. ;(
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-16-2017 05:39 AM
Hi,
First you need to define an Scripted Rest Service in your Target instance as shown below by specifying Name and API id gets automatically generated.
2) Post which you need to define the Resources and select the required HTTP method say as "POST" for creating records in your target instance as shown below:
In the screen shot above I have a field as "Third party incident" based on which I am checking if a record is present in the instance or not.
3) Once the above configurations are done, you need to navigate to your source instance where you need to define your Outbound Rest Message to send the Request to your Target instance as shown below:
In the above screen shot you need to give the Endpoint as your Target instance URl and followed by Base ApI Path field from your Target instance. Save the Form and then define your HTTP method say as POST as shown below:
You need to define your Query parameters under HTTP request Tab which you are planning to pass to the target instance as shown below:
Where ${u_number} and other parameters is the variable you need to define in the Variable Substitution Related List as shown below:
Once this has been done, you need to write an After Insert/Update Business Rule on the required table in your source instance for which you want the data interchange between instances as shown below:
Post this in order to Test this functionality create an Record(say an Incident Ticket if you are doing it for Incident Table) in your source instance the same should be created in your target instance.
Hope this clarifies your doubts:)
Please mark the answer as correct/helpful based on impact.
Regards,
Shloke
Regards,
Shloke