- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
on 03-09-2020 08:12 AM
When you add a multi row variable set (MRVS) to a catalog item, you may be asked to add some validation before the request or task is submitted/updated, do something with those values in the workflow, and/or show the values in a report. As of Orlando, MRVS variables cannot be shown in reports, but skip to the end for a potential workaround that may work for some use cases.
My initial requirement started off easy enough. There was an existing request to order network gear, in multiple quantity, so they needed a way to enter multiple serial numbers once the devices were received. Previous to the MRVS being available, I queried the related Affected CIs to be sure serial numbers had been added to each before a certain task could be closed.
The new way - a MRVS with one variable.
The first requirement after delivering the MRVS was to make sure the number of serial numbers added in the MRVS was equal to the quantity received variable, before the task could be Closed Complete. If you just need to make the MRVS mandatory, add something like this to your onSubmit catalog client script:
if(g_form.getValue('serial_number') == []){ //name of the MRVS
alert('You must enter at least 1 Serial Number!');
return false;
}
To make sure the number of MRVS rows matches the quantity of units received, I added this to an onSubmit catalog client script:
var snlist = g_form.getValue('serial_number'); // name of the MRVS
var obj = JSON.parse(snlist);
var length = obj.length;
var qty = g_form.getValue('v_qty_received');
if(snlist == ''){ // no rows were added to the MRVS
g_form.addErrorMessage('The number of serial numbers entered must match the quantity.');
return false;
}
else if(length != qty){
g_form.addErrorMessage('The number of serial numbers entered must match the quantity.');
return false;
}
A final (for now?) requirement on the client side - before this task can be closed, make sure none of the serial numbers are duplicated - with each other, or with those of existing network devices. This one turned out to be a bit trickier since I was getting the sysid of the variable in the MRVS returned in the JSON, so first I had to replace the sysid with something useful like the variable name:
snlist = snlist.toString().replace(/305886aadbb977807601d3eb5e961932/g,'v_serial_number_mrvs');
Then I passed this JSON formatted string to a script include to first parse the string into a JSON object, then check the array to make sure the same serial number wasn't entered more than once (it has happened):
var obj = JSON.parse(snlist);
var sorted_arr = obj.slice().sort();
for (var k = 0; k < sorted_arr.length - 1; k++) {
if (sorted_arr[k + 1].v_serial_number_mrvs == sorted_arr[k].v_serial_number_mrvs) {
answer = 'Serial number ' + sorted_arr[k].v_serial_number_mrvs + ' is duplicated on the table of serial numbers. Edit or remove one of the entries.';
return answer;
}
}
Finally, looping through the array to query the netgear table for an existing serial number:
for (var i = 0; i < obj.length; i++) {
var gr = new GlideRecord('cmdb_ci_netgear');
gr.addQuery('serial_number', obj[i].v_serial_number_mrvs);
gr.query();
if(gr.next()){
answer = 'Serial number ' + obj[i].v_serial_number_mrvs + ' already exists on a Network Gear CI.';
}
}
return answer;
In my workflow I had to assign each serial number/MRVS row to a newly-created CI.
Luckily, using the MRVS in a server script is a bit more straight-forward.
var snlist = [];
var mrvs = current.variables.serial_number;//return the array of objects stored in the Multi Row Variable Set
snlist = mrvs.v_serial_number_mrvs;//push all of the serial numbers in the mrvs to an array
for(var k=0;k<cilist.length; k++){ // cilist is an array of CIs that were just created
var ci = new GlideRecord('cmdb_ci_netgear');
ci.addQuery('sys_id', cilist[k]);
ci.query();
if(ci.next()){
ci.serial_number = snlist[k];//update each CI with a serial number from the mrvs
ci.update();
}
}
As promised, the potential reporting workaround
A way to show MRVS values on a report, is to simply dump the MRVS values into a new multi-line text field using the above logic/syntax, and add whatever formatting you need for it to make sense. Above in the server script, I could add
current.variables.v_my_text = snlist.join(',');
Admittedly this isn't the most glamorous solution, but it may fill the need for someone needing to see an MRVS on a report.
- 9,980 Views
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi Brad,
Can we generate a report by creating a database view which joins both ritm (sc_req_item) and mrvs (sc_multirow_question_answer) tables?
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
@saipragna Good idea! I added this to a Database View I already had to show RITM, SCTASKS, and some variables - along with the sys_user table since any of the reference and list variables will show the sys_id. Looks like the data is there.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
hi @Brad Bowman and @saipragna ,
First of all, this content has helped a lot in my recent work, so thank you so much for that.
I am trying to create a database view joining HR case table and multi row question table. Please refer to the screenshots for better understanding.
Data base view configuration
Output -
in case of this HR Case, we have not submitted any details for the questions showing in ss, but still on data base view table this is coming with values. which is causing 100+ entries for a single hr case on database view table.
any idea why these junk values are coming ?
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
@b__AnweshaP you are joining on table names instead of a specific record. I would try
mrvs_parent_id=hr_sys_id
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
@Brad Bowman Tagging you as there appears to be an issue with tagging accounts on this forum - when @b__AnweshaP tagged you, our IRC Director (also Brad Bowman) over at TAMU-CC also received an email... We can have him update his subscription and notification settings, but I thought that was bizarre.
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
@Jeremy Dean that's fun! I didn't get an @ notification on that one, so I think my evil/good namesake was tagged instead of me.