- 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-01-2023 08:13 AM
Hi @Michael51 ,
you can use below code and add your newly created task into existing RITM.
var incGr = new GlideRecord('sc_task');
incGr.initialize();
incGr.parent=your_current_RITM_sys_id; // put your ritm sysid
incGr.short_description = 'Database issue'; // set the field value
incGr.category = 'software';
incGr.insert();
Please Mark it Helpful and Accept the Solution so It would solves other query as well.
Thanks
Anand Shukla
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-01-2023 08:16 AM
Hi @Anand Shukla ,
How can I parse RITM number and get pushed to parent id?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-01-2023 08:21 AM
Could you share your payload here so it would be better to understand your use case. Also mention your exact requirement?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-02-2023 01:08 AM - edited 06-02-2023 01:45 AM
Hi @Anand Shukla ,'
Requirement is to Create sc_task to an existing RITM , so in the payload they send the Existing RITM number , we need to take the RITM number and create an Sc_task to that same RITM
I have written below code but it is not working
i have included info message to see what ritm number is coming from payload and in that I could see log as undefined
(function process( /*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
var ritmNumber;
var payload = request.body.data;
if (JSUtil.isEmpty(payload))
return new sn_ws_err.BadRequestError("No data provided");
ritmNumber = payload.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.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);