For Generated RITMs the Workflow is not getting Attached

naren19
Giga Guru

Hi @Ankur Bawiskar / @Ravi Gaurav  /  @Dr Atul G- LNG 
Could you please help on this

Based on the Request Type Entries the RITM's needs to be generated
For Example,
Suppose if the Request Type has two entries in Request then RITM need to be create Two RITM with Attached Workflow.
Currently i am using below script but the Workflow is not getting attached to the Generated RITMs

var requests = JSON.parse(current.u_scratchpad);

for (var i = 0; i < requests.length; i++) {

    var dns1 = requests[i];

    var ritm1 = new GlideRecord('sc_req_item');
    ritm1.initialize();
    ritm1.cat_item.setDisplayValue('DHCP Reservation-RITM');
    ritm1.workflow.setDisplayValue('RITM-DHCP Reservation');
    ritm1.assignment_group.setDisplayValue('SERVER.WINTEL.GLBL.IM.SUP');
    ritm1.short_description = 'DHCP Reservation ' + dns1.request_type;
    ritm1.parent = current.sys_id;
    ritm1.request = current.sys_id;
    ritm1.u_scratchpad = JSON.stringify(requests[i]);
    ritm1.opened_by = current.requested_for;
    ritm1.comments = '[code]<table ng-if = "records.length > 0" class = "table table-striped table-bordered table-hover" cellspacing = "0" width = "100%"><thead><tr><th>Request Name</th><th>Details</th></tr></thead><tbody><tr>' + dns1.html + '</tr></tbody></table>[/code]';

    var ritm_sys_id = ritm1.insert();
}
2 ACCEPTED SOLUTIONS

naren19
Giga Guru

Thanks @Ankur Bawiskar, for the response. 
The CartJS was working but I couldn't be able to add existing Request as Parent to RITM through CartJS and Workflow was note getting attached. I have figured out another way by changing state, approval and stage field of RITM and Workflow was getting attached.

View solution in original post

naren19
Giga Guru

Thanks @Ankur Bawiskar, for the response. 
The CartJS was working but I couldn't be able to add existing Request as Parent to RITM through CartJS and workflow was also not getting attached. I have figured out another way by changing the state, approval, stage field while inserting the RITM and workflow was attaching it was working fine. 

View solution in original post

7 REPLIES 7

Ankur Bawiskar
Tera Patron
Tera Patron

@naren19 

If you use GlideRecord then it won't trigger the workflow for that RITM

please use cartJS API to generate the RITM and don't use GlideRecord

CartJS - Scoped 

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@naren19 

Thank you for marking my response as helpful.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@naren19 

Please mark my response as correct and close the thread if it helped.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

naren19
Giga Guru

Thanks @Ankur Bawiskar, for the response. 
The CartJS was working but I couldn't be able to add existing Request as Parent to RITM through CartJS and Workflow was note getting attached. I have figured out another way by changing state, approval and stage field of RITM and Workflow was getting attached.