Workflow not attached to custom/script generated RITM

Ruchi Kumari1
Tera Expert

Hi,
I am working a catalog, which generates multiple RITM based on users selected on form.
Each user selected should be updated on requested for field on RITM.
I am able to generate multiple RITMs(Default + script generated). but the script generated ritms are not having any workflow attached. There is no "show workflow" related list attached to it. Ideally script generated ritms should have that attached as well. 
I tried creating ritm from both runscript and create task activity but the result is same. Both of them have stage = request approved. Am i missing any other required configuration ?

RuchiKumari1_0-1752239447556.png

Runscript to create ritm :

 
var list = current.variables.requested_for.toString();
var array = list.split(','); //list of requested for users
for (var i = 1; i < array.length; i++) {
var grRitm = new GlideRecord("sc_req_item");
    grRitm.initialize();
    grRitm.cat_item = current.cat_item;
    grRitm.price = current.price;
    grRitm.request = current.request;
    grRitm.requested_for = array[i];
    grRitm.due_date = current.due_date;
    grRitm.short_description = 'test';
    grRitm.assignment_group = current.assignment_group;

    var ritmSysId = grRitm.insert();
}


Script in create task activity (for sc_req_item table):

var list = current.variables.requested_for.toString();
var array = list.split(',');
for (var i = 1; i < array.length; i++) {
    task.request = current.request;
    task.requested_for = array[i];
    task.cat_item = current.cat_item;
}

None of the approach is attaching workflow to the created ritm record. Default RITM is having workflow attached as expected.

8 REPLIES 8

Ankur Bawiskar
Tera Patron
Tera Patron

@Ruchi Kumari1 

you should use Cart API or CartJS API to create REQ and RITM

Without that and if you are using only GlideRecord then workflow or flow won't be attached

check this sample script using CartJS

// sysparm_id means catalog item sysId
// then give variable names and their value
try{
	var cart = new sn_sc.CartJS();
	var item =
		{
			'sysparm_id': '0336c34407d0d010540bf2508c1ed096',
			'sysparm_quantity': '1',
			'variables':{
				'user': '7282abf03710200044e0bfc8bcbe5d03',
				'asset': '00a96c0d3790200044e0bfc8bcbe5dc3',
				'multiple_choice': 'Phoenix',
			}};
	var cartDetails = cart.addToCart(item);
	var checkoutInfo = cart.checkoutCart();
	gs.info('Order details' + JSON.stringify(checkoutInfo));
}
catch(ex){
	gs.info('Exception'+ex);
}

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

Hi @Ankur Bawiskar , but is the cart api not used to place order for catalog item and create respective ritms ?
In my case, user would be submitting request from native view by clicking on order now.
also, there's an existing workflow i have referred which is also creating multiple ritms using workflow activity and for them workflow is getting attached to each ritm. I have kept the configurations similar to that but it's working in my case.

@Ruchi Kumari1 

I have never used GlideRecord insert on RITM to handle such requirement.

Is the workflow or flow getting attached when RITM is inserted using GlideRecord insert?

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

@Ruchi Kumari1 

any update to the above comment?

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