Creating Multiple RITM from one catalog

Abhit
Tera Guru

Hi

I have a requirement, where I have to create multiple request items under a single request using one catalog form.

If the User has selected check-boxes then request item has be created, if does not check any of check-boxes then one RITM has be created.

Requirement is something similar to the Order Guide - New Hire

 

 

find_real_file.png

Thanks,

Kumar

1 ACCEPTED SOLUTION

Harsh Vardhan
Giga Patron

you have to first identify here the number of check box have been checked and based on that using for loop you can create the extra RITM on your request. 

 

Adding Sample code here. use the below code on your workflow run script activity,  Give a try. 

 


var dd = current.variables.check_box;
var dd1 = current.variables.check_box1;
var dd2 = current.variables.check_box2;

var mandatoryVars = [dd,dd1,dd2];

var numTrue = 0;

for (var x = 0; x < mandatoryVars.length; x++) {

	if (mandatoryVars[x] == 'true') {
		numTrue ++;			
	}
}



for(var i = 0 ; i< numTrue ; i ++){
	var gr = new GlideRecord('sc_req_item');
	gr.initialize();
	gr.cat_item = current.cat_item;
	gr.request= current.request;
	gr.insert();
}

 

If my answer helped you, kindly mark it as correct and helpful.

View solution in original post

10 REPLIES 10

Simm
Tera Contributor

Thanks for the time for replying , appreciate it much...
but I already found another class for RITM creator which is already built-in to SN
and would like to share it to our community ..
i'm currently using this object incorporate with your code given .. and so far so good..


// THIS is where new RITM is created
var reqHelper = new GlideappCalculationHelper();
reqHelper.addItemToExistingRequest(current.request, current.cat_item, 1);
reqHelper.rebalanceRequest(current.request);

// Query the newly created RITM, make sure orderbyDESC=sys_created on
var grReqItem = new GlideRecord('sc_req_item');
grReqItem.addQuery('request', current.request);
grReqItem.addQuery('cat_item', current.cat_item);
grReqItem.orderByDesc('sys_created_on');
grReqItem.query();

 

if (grReqItem.next()) {
 
grReqItem.variables.activity_type = current.variables.activity_type; 
grReqItem.variables.area_details = JSON.stringify(newMvrs);
grReqItem.parent = current.sys_id;
grReqItem.update();
///// intentionally double update which i have logic to wait  for request type to be set (my WF logic)
grReqItem.variables.request_type = current.variables.request_type;
grReqItem.update();