Show variables on manually created RITM?

MBarrott
Mega Sage

Curious if there is a way to achieve this. 

 

I have a script which is manually creating a REQ and RITM records, as well as assigning the cat_item to the RITM record. The actual flow itself appears to work successfully and a SCTASK is generated as expected. 

 

The issue I'm seeing (albeit minor) is that the variables are not displaying on the RITM or SCTASK form level. 

 

Is there an optimal way to ensure the variables are also reflected on the form?

 

Script:

        // Create Request
        var reqGR = new GlideRecord('sc_request');
        reqGR.initialize();
        reqGR.requested_for = incCaller;
        reqGR.short_description = incShortDesc;
        reqGR.description = incDesc;
        reqGR.insert();

        // Create RITM
        var ritmGR = new GlideRecord('sc_req_item');
        ritmGR.initialize();
        ritmGR.request = reqGR.sys_id;
        ritmGR.requested_for = incCaller;
        ritmGR.short_description = incShortDesc;
        ritmGR.description = incDesc;
        ritmGR.cat_item = 'd4ef8fc11b21c8106b1843f9cd4bcb93'; // Catalog item sys_id
        ritmGR.insert();

MBarrott_0-1745523109024.png

 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@MBarrott 

you should use Cart API or CartJS to submit request and you can populate variables as well

With this you will start seeing the Variable editor on RITM form and also your flow/workflow will trigger

Something like this

try{

	var cartId = GlideGuid.generate(null);
	var cart = new Cart(cartId);
	//add your requested item to the cart by sys_id of the catalog item
	var item = cart.addItem('0336c34407d0d010540bf2508c1ed096', 1);

	//fill in the variables on the request item form
	cart.setVariable(item, "asset", "00a96c0d3790200044e0bfc8bcbe5dc3");
	cart.setVariable(item, "multiple_choice", "Phoenix");
	var rc = cart.placeOrder();
	gs.info(rc.number);

}
catch(ex){
	gs.info(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

View solution in original post

4 REPLIES 4

DrewW
Mega Sage
Mega Sage

Variables are added to the Requested Item by the ordering process.  So the easiest and quickest way to go about what you would like is to just use the Cart API to order the cat item using your script.

 

 

Ankur Bawiskar
Tera Patron
Tera Patron

@MBarrott 

you should use Cart API or CartJS to submit request and you can populate variables as well

With this you will start seeing the Variable editor on RITM form and also your flow/workflow will trigger

Something like this

try{

	var cartId = GlideGuid.generate(null);
	var cart = new Cart(cartId);
	//add your requested item to the cart by sys_id of the catalog item
	var item = cart.addItem('0336c34407d0d010540bf2508c1ed096', 1);

	//fill in the variables on the request item form
	cart.setVariable(item, "asset", "00a96c0d3790200044e0bfc8bcbe5dc3");
	cart.setVariable(item, "multiple_choice", "Phoenix");
	var rc = cart.placeOrder();
	gs.info(rc.number);

}
catch(ex){
	gs.info(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

@MBarrott 

Hope you are doing good.

Did my reply answer your question?

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 

Sorry for the delay getting back to you. This was a perfect solution and worked without issue! Thanks so much!