BR to create multiple RITMS's based on data in variable
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-15-2024 03:51 AM
HI Team ,
On submittion of catalog item , ritm is created and if its updated, based on values in on one variable names 'uniquereccombo' it should create multiple ritm's.
for example, if variable has key1,key2,key3 values, on update of ritm it should create 2 more ritms.
first ritm variable values should be replaced with key1 other 2 ritm's variable values should be key2, key 3 .
I am using below code in BR , RITM's are getting created but variable value is being key1 in all three.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-15-2024 03:59 AM
Hello @rambo1 ,
Please try the script below and let me know how it works for you:
(function executeRule(current, previous /*null when async*/) {
// Split the 'u_unique_rec_combo' variable value into an array of roles
var roles = current.variables.u_unique_rec_combo.split(',');
if (roles.length > 0) {
// Assign the first role to the current RITM
current.variables.u_unique_rec_combo = roles[0];
current.setWorkflow(false); // Optional: Avoid looping
current.update();
// Loop through the remaining roles to create additional RITMs
for (var i = 1; i < roles.length; i++) {
var newRITM = new GlideRecord('sc_req_item');
newRITM.initialize();
newRITM.parent = current.sys_id;
newRITM.request = current.request;
newRITM.cat_item = current.cat_item;
newRITM.short_description = current.short_description;
newRITM.insert();
// Copy variable values from the original RITM to the new RITM
var originalVariables = new GlideRecord('sc_item_option_mtom');
originalVariables.addQuery('request_item', current.sys_id);
originalVariables.query();
while (originalVariables.next()) {
var newVariable = new GlideRecord('sc_item_option_mtom');
newVariable.initialize();
newVariable.request_item = newRITM.sys_id;
// Set specific role to 'u_unique_rec_combo' variable for each RITM
if (originalVariables.sc_item_option == 'u_unique_rec_combo') {
newVariable.sc_item_option = insertIOL(roles[i]);
} else {
newVariable.sc_item_option = originalVariables.sc_item_option;
newVariable.value = originalVariables.value;
}
newVariable.insert();
}
}
}
// Function to create an entry in 'sc_item_option_list' for the role variable
function insertIOL(roleValue) {
var iol = new GlideRecord('sc_item_option_list');
iol.initialize();
iol.item_option_new = 'ce559a8bfbcd5a1026f7f2b455efdccc';
iol.value = roleValue;
return iol.insert();
}
})(current, previous);
If it doesn’t work for you, please let me know. I’ve implemented this functionality before, so I’d be happy to take a closer look at both scripts and help troubleshoot.
Please Mark ✅Correct if this solves your query and also mark 👍Helpful if you find my response worthy based on the impact.
Regards,
Aniket
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-15-2024 04:48 AM
Still the same issue .
I have submitted item with key1,key2,key3 as value in 'uniqureccombo' variable , after that updted ritm, it created 3 ritms.
but 'uniquereccombo' variable value is key1 in all three RITM's
I have added one line