- 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 06:01 AM
@Michael51 this might be acl issue on scripted rest resource.
Create a acl with the role you are using for integration user and add the acl to resource.
Acl should be of type rest endpoint.
ServiceNow Community Rising Star, Class of 2023