How to send response in scripted rest API's
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-12-2021 06:55 AM
Hi,
I have a requirement related to inbound integration , using scripted rest API's , import set table and transform map.
I am receiving two fields in the request payload from the third part tool to our servicenow.
They are hiting our scripted rest api. We have the scenario for update. We have created a API using put method.
now the requirement is that third party tool is hiting our scripted rest API and sending two fields in the request payload
{ "abc field" :"sys_id of the record" ,
" pqr field" : "value" }
Now firstly when the third party tool hits our api , it will store the data in import set table and after running the transform , we will send the data to target tables and update the related records in target table.
And in the response we have to provide the status code to the third party tool.
So how can we achieve this solution , I have created the scripted rest api , resource path and import set table.
But please help me with the logic that needs to be written in scripted rest API to send the response status to third party tool.
Thanks
Utkarsh
- Labels:
-
Integrations
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-12-2021 07:54 AM
Hi,
sample script to insert into staging table
Once you insert into staging table and you have transform map, field map etc already present the transformation will happen
(function process(/*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
var reqbody = request.body.dataString;
try{
var parser = new global.JSON();
var parsedData = parser.decode(reqbody);
// insert the record into staging table
var gr = new GlideRecord('u_incident');
gr.initialize();
gr.u_description = parsedData.description;
gr.u_notes = parsedData.notes;
gr.insert();
var res = {};
res["status"] = "Success";
res["message"] = "Record submitted for transformation";
response.setBody(JSON.stringify(res));
}
catch(ex){
var res = {};
res["status"] = "Error";
res["message"] = ex.message;
response.setBody(JSON.stringify(res));
}
})(request, response);
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-12-2021 07:56 AM
some other links
Import Set API - multiple records
Bulk Upload in Staging Table Though Scripted RestApi - solution shared by me here
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-12-2021 10:48 PM
Hello
Thanks for the reply , here I am having a requirement as third party tool is hitting our PUT scripted rest API for the update.
They wants to update two records in the target table but here we are using the import set tables and transform map.
In the PUT API , they will send the sys_id of the record and will update the two fields in the target table.
So please help me to how to implement this requirement from scratch.
I have created a scripted rest api and a resource path with PUT api. In this firstly we insert the data in import set tables and then with the help of transform , update the two desired fields in target table.
and after the successful update , we have to send the response as success and a response status 200 to third party tool.
PLEASE help me with the script and logic that I can write in the scripted rest api to implement the same which includes , the import set logic, transform map and to send the status as success or failure with status code.
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-15-2021 10:19 PM
I have already shared the approach
Once you insert data into import set table from script the transformation begins and data would be transformed
Let me know if I have answered your question.
If so, please mark appropriate response as correct & helpful so that this thread can be closed and others can be benefited by this.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-26-2021 06:52 AM
Hope you are doing good.
Did my reply answer your question?
Would you mind marking the best matching answer as correct and helpful, to close this thread?
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader