How to copy/print MRVS (Multi row variable set) values to catalog task release management?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-13-2024 11:48 PM
Hi Community,
My catalog item contains MRVS which contains reference (application to select), list collector. How do we copy these values selected onto the release management work notes?
Tricky part is, Each row with different reference variable selected will create a catalog task per row . There can be multiple tasks generated. And that catalog task description should contain only that row variable values.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-14-2024 03:31 PM
Here's the method I like to use in a Workflow Run Script or Business Rule to retrieve the MRVS data and loop through the contents. Since this is a JSON string, I don't think you can use getDisplayValue or dot-walk, so you'll need to do a GlideRecord to lookup the reference and list sys_ids. If you have one MRVS variable named cmdb_name that is a reference to the cmdb_ci table, and one MRVS variable named users that is a list collector referencing the sys_user table, here is one way to get values other than sys_ids to a work note:
var tes = current.variables.cmdb_basic_tes; //MRVS internal name
var totalRows = tes.getRowCount();
for (var i = 0; i < totalRows; i++) {
gs.info('test');
var row = tes.getRow(i);
var cmdbGR = new GlideRecord('cmdb_ci'); //reference variable table
if (cmdbGr.get(row.cmdb_name)) { //mrvs reference variable name
gs.info('test2');
var name1 = cmdbGR.name; //field from reference table to display in work note
}
var usrArr = [];
var usrGR = new GlideRecord('sys_user'); //list collector variable list table
usrGR.addQuery('sys_id', 'IN', row.users); //mrvs list collector variable name
usrGR.query();
while (usrGR.next()) {
gs.info('test2');
usrArr.push(usrGR.user_name); //field on list table to display in work notes
}
current.work_notes=name1+'||'+usrArr.join(', ');
}
This would add a work note for each row of the MRVS.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-16-2024 01:49 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-16-2024 09:31 AM
Which logs are you receiving? Add more, with script variable names, and make sure the logs are unique so that you can see what is happening in the script - how far it is getting, values stored in script variables, records returned in GlideRecord queries,...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-14-2024 06:15 PM - edited 09-14-2024 06:39 PM
In workflow
var mrvsData = current.variables.u_mrvs;
if (mrvsData) {
var x= JSON.parse(mrvsData);
for (var i = 0; i < x.length; i++) {
var row = x[i];
Var gr= new GlideRecord( tableName);
gr.get(row.u_application)
var y= gr.name ;
var tsk=new GlideRecord ( 'sc_task');
tsk.intialize();
task.descrption=y;
task.insert();
}
}