Create request item from multi row variable set
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2020 02:38 AM
Hi,
I've got a requirement to created as many RITMs as there are rows in the multi-row variable set.
I'm doing this using workflow.
User can request mulitiple as in one request.
It should create multiple RITM for each row and each RITM goes for approval
Can anyone help me on this.
Thanks,
Sowmya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2020 02:52 AM
You can use this in workflow run script using Cart API
Ensure you give valid catalog item sys_id and valid variable names and values
Once those respective number of RITMs are generated it would trigger workflows for those individual RITMs
var values = current.variables.mrvsVariableName; // give here the MRVS variable name
var parser = JSON.parse(values);
for(var i=0;i<parser.length;i++){
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('4054428fdb151f0097679ec6db9619c0', 1);
//fill in the variables on the request item form
cart.setVariable(item,"u_requested_for", "e80edd6edbec6bc097275e25ca9619a4");
cart.setVariable(item,"contact_number", "0");
cart.setVariable(item,"assignment_group", "87ec1c342b2e71406c487fb5a8da1524");
cart.setVariable(item,"application_service", "cdedfbcedb0f9744c291c170ba9619a7");
var rc = cart.placeOrder();
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2020 03:25 AM
Hi,
I'm refering this article https://community.servicenow.com/community?id=community_article&sys_id=ba4d5295db18a810fa192183ca9619a7
I'm adding two row but it's creating 3 RITM
Can you suggest on this.
below is the script:
var rowCount = current.variables.authorization_limit1.getRowCount(); //This includes the internal name of the multi row variable set which is "authorization_limit1"
for (var i = 0; i < rowCount; i++) {
//Define variables that will be the same on each RITM. Add more as required
var req = current.request;
var reqBy = current.variables.requested_by;
//Grab each row of variables that will be different on each RITM
var row = current.variables.authorization_limit1.getRow(i);
var user = row.emp_name;
var id = row.emp_id;
var ledg = row.ledg_name;
var code = row.cur_code;
var lmt=row.authn_limit;
//Crete a RITM for each row
var rec = new GlideRecord ('sc_req_item');
rec.cat_item = 'd1f06caf1b1b9c14419998ac0a4bcbdd';//catalog item for gl authorization item NOTE: This is REQUIRED to kick off the individual workflow created by each MRVS line item
rec.request = req;
rec.request.requested_for = reqBy;
//rec.approval = 'requested';
rec.state = 1;
rec.stage = 'requested';
//rec.assignment_group = 'ea42046613059200a01f3ea32244b0a0'; //sys_id of the Human Resources group
//rec.short_description = "Off-boarding for user "+nam;
//rec.description = "Off-board this user: \n - Name: "+nam+"\n - Employee Number: "+num+"\n - Manager: "+mgr;
rec.insert();
}
After creating RITM I need send it for approval for each row means for RITM
Please suggest.
Thanks,
Sowmya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2020 03:34 AM
Hi,
please try adding logs for getting the count
OR
try this script
var values = current.variables.authorization_limit1;
var parser = JSON.parse(values);
for (var i = 0; i < parser.length; i++) {
//Define variables that will be the same on each RITM. Add more as required
var req = current.request;
var reqBy = current.variables.requested_by;
//Grab each row of variables that will be different on each RITM
var row = current.variables.authorization_limit1.getRow(i);
var user = row.emp_name;
var id = row.emp_id;
var ledg = row.ledg_name;
var code = row.cur_code;
var lmt=row.authn_limit;
//Crete a RITM for each row
var rec = new GlideRecord ('sc_req_item');
rec.cat_item = 'd1f06caf1b1b9c14419998ac0a4bcbdd';//catalog item for gl authorization item NOTE: This is REQUIRED to kick off the individual workflow created by each MRVS line item
rec.request = req;
rec.request.requested_for = reqBy;
//rec.approval = 'requested';
rec.state = 1;
rec.stage = 'requested';
//rec.assignment_group = 'ea42046613059200a01f3ea32244b0a0'; //sys_id of the Human Resources group
//rec.short_description = "Off-boarding for user "+nam;
//rec.description = "Off-board this user: \n - Name: "+nam+"\n - Employee Number: "+num+"\n - Manager: "+mgr;
rec.insert();
}
Post RITM creation it would automatically start the workflow
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-12-2021 05:57 AM
Hope you are doing good.
Did my reply answer your question?
If so, please mark appropriate response as correct & helpful so that the question will appear as resolved for others who may have a similar question in the future.
Thanks!
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader