- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-01-2023 08:02 AM
Hello All,
I have an requirement to create an catalog task and associate to Existing RITM , So can I please have some sample script to develop this
So in the payload what details do they need to send etc
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-02-2023 02:17 AM
update as this
Ensure you link that sc_task with that RITM and REQ
Also I assume 3rd party will send data like this
{
"request_item":"RITM001"
}
(function process( /*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
var ritmNumber;
var payload = request.body.dataString;
if (JSUtil.isEmpty(payload))
return new sn_ws_err.BadRequestError("No data provided");
var parsedData = JSON.parse(payload);
ritmNumber = parsedData.request_item;
var ritm = new GlideRecord('sc_req_item');
ritm.addQuery('number','ritmNumber');
ritm.query();
if(ritm.next()){
var gr = new GlideRecord('sc_task');
gr.request_item = ritm.getUniqueValue();
gr.request = ritm.request;
gr.initialize();
var taskId = gr.insert();
// Return the created SC Task details in the response
var responseBody = {
number: gr.number.getDisplayValue(),
};
response.setStatus(201); // 201 - Created
response.setBody(responseBody);
}
})(request, response);
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-02-2023 03:22 AM
@Michael51 Use updated code below to add the assignment group as well
ServiceNow Community Rising Star, Class of 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-02-2023 05:39 AM
Hello @jaheerhattiwale ,
Am getting following error while Testing the API
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-02-2023 05:41 AM
@Michael51 You are trying it from postman? The scripted rest resource url (end point) you use used is not correct i think. please check.
ServiceNow Community Rising Star, Class of 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-02-2023 05:43 AM
@jaheerhattiwale , same works in Rest API but not here in postman
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-02-2023 05:45 AM
@Michael51 Send screenshot of scripted rest resource record and postman?
ServiceNow Community Rising Star, Class of 2023
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-02-2023 05:53 AM