petercawdron
Kilo Guru

Unfortunately, ServiceNow's OOB Flow actions do not copy multi-row variable sets, so if you want your MRVS to be visible on a catalog task you have to navigate back to the requested item related to them. 

Here's a nice little work around using a client script and a script includes, using a little jQuery to insert a table on-the-fly that looks like this on the catalog task...

find_real_file.png

This approach caters for any number of multi-row variable sets on a requested item and will look up select box and reference values. Here's how it works...

An on load client script runs, using a Glide Ajax call to check to see if there are any mrvs. Don't forget to turn OFF the isolate script option on your client script or it won't be able to access jQuery. Your client script should be defined on the table sc_task.  

function onLoad() {

	if(g_form.getValue('request_item')!=''){
		
		//Check for a multi-row variable set
		var gaMRVS = new GlideAjax('multRowVariableSets');
		gaMRVS.addParam('sysparm_name','getQA');
		gaMRVS.addParam('sysparm_sys_id',g_form.getValue('request_item'));
		gaMRVS.getXMLAnswer(displayResults);

	}
	
	///////////////////////////////////////////////////////
	function displayResults(results){
		
		var allMRVS = JSON.parse(results), htmlTable = '';

		allMRVS.forEach(function(mvrs){

			if(mvrs.details.length !=0){

				//First, sort results by row then by order
				mvrs.details.sort(function(a, b) {if (a.row === b.row) {return a.order > b.order ? 1 : -1;} return a.row > b.row ? 1 : -1;});

				//We'll add our MRVS as a table beneath the description field
				htmlTable+= '<div class="form-group"><div><label class="col-xs-12 col-md-1_5 col-lg-2 control-label"><span aria-label="" data-dynamic-title="" mandatory="false" oclass="" class=" "></span><span title="" class="label-text" data-html="false" data-original-title="" aria-expanded="false">'+mvrs.name+'</span></label></div><div class="col-xs-10 col-md-9 col-lg-8 form-field input_controls"><table style="border-collapse: collapse;border-right:1px solid silver;border-bottom:1px solid silver;width:100%"><tr>';

				//Get the first row number
				var rowNumber = mvrs.details[0].row;

				//get column headers
				mvrs.details.forEach(function(thisEntry){
					if(thisEntry.row == rowNumber){
						htmlTable+= '<td style="padding:10px !important;border-left:1px solid silver;border-top:1px solid silver;background-color:WhiteSmoke;">'+thisEntry.question+'</td>';
					}
				});
				
				rowNumber = '';
				
				//add each row
				mvrs.details.forEach(function(thisEntry){
					//insert a new row each time the row number changes
					if(thisEntry.row != rowNumber) htmlTable+= '</tr><tr>';
					//add each individual cell value (knowing it has been sorted correctly so they'll all be in order)
					htmlTable+= '<td style="padding:10px !important;border-left:1px solid silver;border-top:1px solid silver;">'+thisEntry.value+'</td>';
					rowNumber = thisEntry.row;
				});
 
				htmlTable+= '</tr></table></div>';
			}
		});

		jQuery('#element\\.sc_task\\.description').after(htmlTable);
	}
}

Then at the back end all we need is a Script Include to do the heavy lifting for us... Make sure and the script include is client callable.

var multRowVariableSets = Class.create();
multRowVariableSets.prototype = Object.extendsObject(AbstractAjaxProcessor, {

	getQA: function(){
		//Returns a JSON object representing all the MRVS for a particular requested item along with their values
		var sys_id = this.getParameter('sysparm_sys_id') || '2a175e5edb830090b3da126b3a9619b1';
		var allMRVS = [];
		var ritm = new GlideRecord('sc_req_item');
		if(ritm.get(sys_id)){

			//loop through the variables looking for multi-row variable sets
			for(var eachVar in ritm.variables){
				
				//found one!
				if(ritm.variables[eachVar].isMultiRow()){

					//////////////////////////////////////////
					//get Multi-Row Variable Set structure
					var mrvsDefintion = {}, title='';
					var mrvsStructure = new GlideRecord('item_option_new');
					mrvsStructure.addEncodedQuery('active=true^variable_setISNOTEMPTY^variable_set.internal_name=' + eachVar);
					mrvsStructure.orderBy('order');
					mrvsStructure.query();

					while(mrvsStructure.next()){
						//What is the title of this MRVS?
						if(title=='') title = mrvsStructure.variable_set.title.toString();
						//What about each of the variables
						mrvsDefintion[mrvsStructure.name.toString()] = {"name" :    mrvsStructure.name.toString(),
																		"question": mrvsStructure.question_text.toString(),
																		"sys_id":   mrvsStructure.sys_id.toString(),
																		"type":     mrvsStructure.type.getDisplayValue(),
																		"table":    mrvsStructure.type.getDisplayValue()=="Reference" ? mrvsStructure.reference.getValue() : "",
																		"order":    mrvsStructure.order.toString(),
																		"row":      "",
																		"value":    ""};
					}

					//////////////////////////////////////////
					//get the Multi-Row Variable Set values
					var mrvsValue = [];
					var mrvsAnswers = new GlideRecord('sc_multi_row_question_answer');
					mrvsAnswers.addEncodedQuery('parent_id='+sys_id+'^variable_set.internal_name='+ eachVar);
					mrvsAnswers.orderBy('row_index');
					mrvsAnswers.query();

					while(mrvsAnswers.next()){
						var thisVariable = mrvsAnswers.item_option_new.name.toString();
						if(mrvsDefintion.hasOwnProperty(thisVariable)){
							//Get value 
							var thisValue = mrvsAnswers.value.toString();
							
							//if this is a reference field get the display value
							if(mrvsDefintion[thisVariable].type=='Reference' && mrvsDefintion[thisVariable].table!=''){

								var getDisplayVal = new GlideRecord(mrvsDefintion[thisVariable].table);
								if(getDisplayVal.get(thisValue)){
									thisValue = getDisplayVal.getDisplayValue();
								}
							}
							
							//If this is a select box with choices, get the question_choice (display value)
							if(mrvsDefintion[thisVariable].type=='Select Box'){

								var getQuestionChoice = new GlideRecord('question_choice');
								getQuestionChoice.addEncodedQuery('question='+ mrvsDefintion[thisVariable].sys_id +'^value=' + thisValue);
								getQuestionChoice.query();
								if(getQuestionChoice.next()){
									thisValue = getQuestionChoice.text.toString();
								}
							}
							
							mrvsDefintion[thisVariable].value = thisValue;
							mrvsDefintion[thisVariable].row   = mrvsAnswers.row_index.toString();
							mrvsValue.push(JSON.parse(JSON.stringify(mrvsDefintion[thisVariable])));//push in a clean object
						}
					}
					allMRVS.push({"name": title, "details": mrvsValue});
				}
			}
		}
		return JSON.stringify(allMRVS);
	},

	type: 'multRowVariableSets'
});

Have fun

Comments
Madhulika2
Tera Explorer

Have this been tried ?

Johan Arif Clav
Tera Contributor

Hi @petercawdron 

your solution works perfectly to me. It was exactly what I was looking for. Thank you so much. 


Just one thing to add: the client script has to be defined to the table sc_task and the script include has to be client callable in order to everything work good. Sorry about the clarification, but it took me a while to figure it out. 


One more time, thank you. 🙂 

petercawdron
Kilo Guru

Ah, yes... forgot to add those points. I'll update the article

petercawdron
Kilo Guru

Yes, it works really well

Baggies
Kilo Guru

Hello, is this still working for you? I tried to implement this option, and had no joy at all. Thanks

Rodrigo5
Mega Contributor

Thank you ! It worked

Shane J
Tera Guru

Copying is the greatest form of flattery

With that in mind, I re-purposed your scripts for use in a Notification Mail Script that will show MRVs in Notifications for either RITMs or Approvals for RITMs.  I wish I had found this two days ago before I started trying to solution this.

 

You should be able to create a Notification Mail Script with whatever name you want to give it, then reference your script in Notifications for Requested Items or Approvals tables. 

 

Note that this treats MRVs separately from other variables in regard to displaying them in a Notification.  I haven't tried to build the holy grail that will show all variables, in the proper order, as of yet.

(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
    /* Optional EmailOutbound */
    email, /* Optional GlideRecord */ email_action,
    /* Optional GlideRecord */
    event) {

    if (current.sys_class_name == 'sc_req_item') { //Requested Items only
        var rec = current.sys_id;
        var recV = current.variables;
    }
	if (current.sysapproval.getRefRecord().getTableName() == 'sc_req_item') { //Approvals for Requested items only
        rec = current.sysapproval.sys_id;
        recV = current.sysapproval.variables;
    }
	
    var allMRVS = [];
    //loop through the variables looking for multi-row variable sets
    for (var eachVar in recV) {
        //found one!
        if (recV[eachVar].isMultiRow()) {
            //////////////////////////////////////////
            //get Multi-Row Variable Set structure
            var mrvsDefintion = {},
                title = '';
            var mrvsStructure = new GlideRecord('item_option_new');
            mrvsStructure.addEncodedQuery('active=true^variable_setISNOTEMPTY^variable_set.internal_name=' + eachVar);
            mrvsStructure.orderBy('order');
            mrvsStructure.query();

            while (mrvsStructure.next()) {
                //What is the title of this MRVS?
                if (title == '') title = mrvsStructure.variable_set.title.toString();
                //What about each of the variables
                mrvsDefintion[mrvsStructure.name.toString()] = {
                    "name": mrvsStructure.name.toString(),
                    "question": mrvsStructure.question_text.toString(),
                    "sys_id": mrvsStructure.sys_id.toString(),
                    "type": mrvsStructure.type.getDisplayValue(),
                    "table": mrvsStructure.type.getDisplayValue() == "Reference" ? mrvsStructure.reference.getValue() : "",
                    "order": mrvsStructure.order.toString(),
                    "row": "",
                    "value": ""
                };
            }

            //get the Multi-Row Variable Set values
            var mrvsValue = [];
            var mrvsAnswers = new GlideRecord('sc_multi_row_question_answer');
            mrvsAnswers.addEncodedQuery('parent_id=' + rec + '^variable_set.internal_name=' + eachVar);
            mrvsAnswers.orderBy('row_index');
            mrvsAnswers.query();

            while (mrvsAnswers.next()) {
                var thisVariable = mrvsAnswers.item_option_new.name.toString();
                if (mrvsDefintion.hasOwnProperty(thisVariable)) {
                    //Get value 
                    var thisValue = mrvsAnswers.value.toString();
                    //if this is a reference field get the display value
                    if (mrvsDefintion[thisVariable].type == 'Reference' && mrvsDefintion[thisVariable].table != '') {
                        var getDisplayVal = new GlideRecord(mrvsDefintion[thisVariable].table);
                        if (getDisplayVal.get(thisValue)) {
                            thisValue = getDisplayVal.getDisplayValue();
                        }
                    }

                    //If this is a select box with choices, get the question_choice (display value)
                    if (mrvsDefintion[thisVariable].type == 'Select Box') {
                        var getQuestionChoice = new GlideRecord('question_choice');
                        getQuestionChoice.addEncodedQuery('question=' + mrvsDefintion[thisVariable].sys_id + '^value=' + thisValue);
                        getQuestionChoice.query();
                        if (getQuestionChoice.next()) {
                            thisValue = getQuestionChoice.text.toString();
                        }
                    }
                    mrvsDefintion[thisVariable].value = thisValue;
                    mrvsDefintion[thisVariable].row = mrvsAnswers.row_index.toString();
                    mrvsValue.push(JSON.parse(JSON.stringify(mrvsDefintion[thisVariable]))); //push in a clean object
                }
            }
            allMRVS.push({
                "name": title,
                "details": mrvsValue
            });
        }
    }

    var results = JSON.stringify(allMRVS);
    var allMRVS_b = JSON.parse(results);
    allMRVS_b.forEach(function(mvrs) {
        if (mvrs.details.length != 0) {
            //First, sort results by row then by order
            mvrs.details.sort(function(a, b) {
                if (a.row === b.row) {
                    return a.order > b.order ? 1 : -1;
                }
                return a.row > b.row ? 1 : -1;
            });
            //We'll add our MRVS as a table beneath the description field
            template.print('<div class="form-group"><div><label class="col-xs-12 col-md-1_5 col-lg-2 control-label"><span aria-label="" data-dynamic-title="" mandatory="false" oclass="" class=" "></span><span title="" class="label-text" data-html="false" data-original-title="" aria-expanded="false"><strong>' + mvrs.name + '</strong></span></label></div><div class="col-xs-10 col-md-9 col-lg-8 form-field input_controls"><p><table style="border-collapse: collapse;border-right:1px solid silver;border-bottom:1px solid silver;width:96%"><tr>');
            //Get the first row number
            var rowNumber = mvrs.details[0].row;
            //get column headers
            mvrs.details.forEach(function(thisEntry) {
                if (thisEntry.row == rowNumber) {
                    template.print('<td style="padding:10px !important;border-left:1px solid silver;border-top:1px solid silver;background-color:WhiteSmoke;">' + thisEntry.question + '</td>');
                }
            });
            rowNumber = '';
            //add each row
            mvrs.details.forEach(function(thisEntry) {
                //insert a new row each time the row number changes
                if (thisEntry.row != rowNumber) template.print('</tr><tr>');
                //add each individual cell value (knowing it has been sorted correctly so they'll all be in order)
                template.print('<td style="padding:10px !important;border-left:1px solid silver;border-top:1px solid silver;">' + thisEntry.value + '</td>');
                rowNumber = thisEntry.row;
            });
            template.print('</tr></table></p></div>');
        }
    });
    //    } //end Requested Items
})(current, template, email, email_action, event);

 

 

 

 

kashyap6
Tera Contributor

How can we add it in variables rather than under description?

harika26
Tera Contributor

Do we need to make any change in order to define the client script on the sc_task table?

petercawdron
Kilo Guru

The following line positions the table. You just have to identify the element on the page you want it associated with and substitute that in here. 

jQuery('#element\\.sc_task\\.description').after(htmlTable);
petercawdron
Kilo Guru

No, just added it as a regular client script but turn off isolate script.

Also, don't forget to make your script include client callable

harika26
Tera Contributor

I did it the same way. I am not knowing y the script is not working.

ar1
Kilo Sage

Hi Peter,

Thanks for the post.

But we need to copy the multi row variable set variables from first RITM to second RITM, both the RITM tickets under one REQ ticket.

 If we select more than one row while raising the request, Only one row is coping from the first RITM ticket.

we're using the below script in workflow run script activity:

Advance thanks for the support

 

var ritmrcd = new GlideRecord('sc_req_item');
var currntritm = current.sys_id;
var sritm;
var sritmnum;
var rowind = [];
var partbl;
var ssd = 'Account Access';
ritmrcd.addQuery('request',current.request);
ritmrcd.addQuery('short_description',ssd);
ritmrcd.query();
while(ritmrcd.next()){
sritm = ritmrcd.sys_id;
sritmnum = ritmrcd.number;
ritmrcd.order_guide = current.order_guide;
ritmrcd.update();
}

var newitmoption = new GlideRecord('sc_item_option_mtom');
var itmoption = new GlideRecord('sc_item_option_mtom');
itmoption.addQuery('request_item',currntritm);
itmoption.query();
while(itmoption.next()){
newitmoption.initialize();
newitmoption.request_item = sritm;
newitmoption.sc_item_option = itmoption.sc_item_option;
newitmoption.insert();
}

var mrvs = new GlideRecord('sc_multi_row_question_answer');

mrvs.addQuery('parent_id',currntritm);
mrvs.addQuery('variable_set','414f42501b34e050b76b98221a4bcb9f');
mrvs.query();
if(mrvs.next()){
rowind.push(mrvs.row_index.toString());
}


var svmrvs = new GlideRecord('sc_multi_row_question_answer');

svmrvs.addQuery('parent_id',currntritm);
svmrvs.addQuery('variable_set','61f60aec1b3c2450b76b98221a4bcb23');
svmrvs.query();
if(svmrvs.next()){
rowind.push(svmrvs.row_index.toString());
}


var smrvs = new GlideRecord('sc_multi_row_question_answer');
smrvs.addQuery('row_index','IN',rowind);
smrvs.addQuery('parent_table_name','sc_cart_item');
smrvs.query();
while(smrvs.next()){
smrvs.parent_table_name = 'sc_req_item';
smrvs.parent_id = sritm;
smrvs.update();
}

 

Brian36
Tera Explorer

Been using this solution for a while and noticed that the code to get display value for reference field did not account for "list collector" variables.

Modified the below code, and so far it seems to work.

while(mrvsStructure.next()){
	//What is the title of this MRVS?
	if(title=='') title = mrvsStructure.variable_set.title.toString();
	//What about each of the variables
	mrvsDefintion[mrvsStructure.name.toString()] = 
		{"name" :    mrvsStructure.name.toString(),
		"question": mrvsStructure.question_text.toString(),
		"sys_id":   mrvsStructure.sys_id.toString(),
		"type":     mrvsStructure.type.getDisplayValue(),
		"table":    mrvsStructure.type.getDisplayValue()=="Reference" ? mrvsStructure.reference.getValue() : mrvsStructure.type.getDisplayValue()=="List Collector" ? mrvsStructure.list_table.getValue() : "",
		"order":    mrvsStructure.order.toString(),
		"row":      "",
		"value":    ""};
//if this is a reference field get the display value
if((mrvsDefintion[thisVariable].type=='Reference' || mrvsDefintion[thisVariable].type=='List Collector') && mrvsDefintion[thisVariable].table!=''){
	var getDisplayVal = new GlideRecord(mrvsDefintion[thisVariable].table);
	if(getDisplayVal.get(thisValue)){
		thisValue = getDisplayVal.getDisplayValue();
	}
}
DiNesh77
Tera Contributor

@Peter Cawdron 

I have tried the above script to pass the Multirow variable set from RITM to sc task but it did not work.
 
Currently any modification is necessary in Rome version to make the script work?.
 
Thanks

 

peter_cawdron_p
Giga Expert

Sorry, I'm no longer working with ServiceNow so you'll have to dive in and play with the code. 

Insert the following inside the WHILE loop and you'll be able to look at the structure of the object to see if it has changed now that Rome has been released. 

gs.log(JSON.stringify(mrvsStructure,3),'Multi-Row Variable Set');

 If you add this, you'll be able to go into your system logs and search on the source 'Multi-Row Variable Set' to find the structure of the object. Then just change the code accordingly. 

Also, I'd start with Brian's code as it looks like he's already figured a lot of this out, so add the gs.log into his code and test with that. Just don't forget to comment out the gs.log before you move into production (or you'll clog up your logs with more junk than is needed)

DiNesh77
Tera Contributor

@peter.cawdron.personal 

So good of you to respond for my query .

And i have tried the brian's script but no luck.

Also i have done gs.log to find the structure of the object.

I will paste my code here ,kindly let me know if any changes required.

 

Script include:

var multRowVariableSets = Class.create();
multRowVariableSets.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    getQA: function() {
        //Returns a JSON object representing all the MRVS for a particular requested item along with their values
        var sys_id = this.getParameter('sysparm_sys_id') || '17ad8cdadb7330102b2cce4e1396192f';
        var allMRVS = [];
        var ritm = new GlideRecord('sc_req_item');
        if (ritm.get(sys_id)) {

            //loop through the variables looking for multi-row variable sets
            for (var eachVar in ritm.variables) {

                //found one!
                if (ritm.variables[eachVar].isMultiRow()) {

                    //////////////////////////////////////////
                    //get Multi-Row Variable Set structure
                    var mrvsDefintion = {},
                        title = '';
                    var mrvsStructure = new GlideRecord('item_option_new');
                    mrvsStructure.addEncodedQuery('active=true^variable_setISNOTEMPTY^variable_set.internal_name=' + eachVar);
                    mrvsStructure.orderBy('order');
                    mrvsStructure.query();
                    while (mrvsStructure.next()) {
                        //What is the title of this MRVS?
                        if (title == '') title = mrvsStructure.variable_set.title.toString();
                        //What about each of the variables
                        mrvsDefintion[mrvsStructure.name.toString()] = {
                            "name": mrvsStructure.name.toString(),
                            "question": mrvsStructure.question_text.toString(),
                            "sys_id": mrvsStructure.sys_id.toString(),
                            "type": mrvsStructure.type.getDisplayValue(),
                            "table": mrvsStructure.type.getDisplayValue() == "Reference" ? mrvsStructure.reference.getValue() : mrvsStructure.type.getDisplayValue() == "List Collector" ? mrvsStructure.list_table.getValue() : "",
                            "order": mrvsStructure.order.toString(),
                            "row": "",
                            "value": ""
                        };
                    }

                    //////////////////////////////////////////
                    //get the Multi-Row Variable Set values
                    var mrvsValue = [];
                    var mrvsAnswers = new GlideRecord('sc_multi_row_question_answer');
                    mrvsAnswers.addEncodedQuery('parent_id=' + sys_id + '^variable_set.internal_name=' + eachVar);
                    mrvsAnswers.orderBy('row_index');
                    mrvsAnswers.query();

                    while (mrvsAnswers.next()) {
                        var thisVariable = mrvsAnswers.item_option_new.name.toString();
                        if (mrvsDefintion.hasOwnProperty(thisVariable)) {
                            //Get value 
                            var thisValue = mrvsAnswers.value.toString();

                            //if this is a reference field get the display value
                            if (mrvsDefintion[thisVariable].type == 'Reference' && mrvsDefintion[thisVariable].table != '') {

                                var getDisplayVal = new GlideRecord(mrvsDefintion[thisVariable].table);
                                if (getDisplayVal.get(thisValue)) {
                                    thisValue = getDisplayVal.getDisplayValue();
                                }
                            }

                            //If this is a select box with choices, get the question_choice (display value)
                            if (mrvsDefintion[thisVariable].type == 'Select Box') {

                                var getQuestionChoice = new GlideRecord('question_choice');
                                getQuestionChoice.addEncodedQuery('question=' + mrvsDefintion[thisVariable].sys_id + '^value=' + thisValue);
                                getQuestionChoice.query();
                                if (getQuestionChoice.next()) {
                                    thisValue = getQuestionChoice.text.toString();
                                }
                            }

                            mrvsDefintion[thisVariable].value = thisValue;
                            mrvsDefintion[thisVariable].row = mrvsAnswers.row_index.toString();
                            mrvsValue.push(JSON.parse(JSON.stringify(mrvsDefintion[thisVariable]))); //push in a clean object
                        }
                    }
                    allMRVS.push({
                        "name": title,
                        "details": mrvsValue
                    });
                }
            }
        }
		gs.log(JSON.stringify(mrvsStructure,3),'Multi-Row Variable Set');
        return JSON.stringify(allMRVS);
		

    },


    type: 'multRowVariableSets'
});

 

Client script:

 

function onLoad() {
   //Type appropriate comment here, and begin script below
 if(g_form.getValue('request_item')!=''){
		
		//Check for a multi-row variable set
		var gaMRVS = new GlideAjax('multRowVariableSets');
		gaMRVS.addParam('sysparm_name','getQA');
		gaMRVS.addParam('sysparm_sys_id',g_form.getValue('request_item'));
		gaMRVS.getXMLAnswer(displayResults);

	}
	
	///////////////////////////////////////////////////////
	function displayResults(results){
		
		var allMRVS = JSON.parse(results), htmlTable = '';

		allMRVS.forEach(function(mvrs){

			if(mvrs.details.length !=0){

				//First, sort results by row then by order
				mvrs.details.sort(function(a, b) {if (a.row === b.row) {return a.order > b.order ? 1 : -1;} return a.row > b.row ? 1 : -1;});

				//We'll add our MRVS as a table beneath the description field
				htmlTable+= '<div class="form-group"><div><label class="col-xs-12 col-md-1_5 col-lg-2 control-label"><span aria-label="" data-dynamic-title="" mandatory="false" oclass="" class=" "></span><span title="" class="label-text" data-html="false" data-original-title="" aria-expanded="false">'+mvrs.name+'</span></label></div><div class="col-xs-10 col-md-9 col-lg-8 form-field input_controls"><table style="border-collapse: collapse;border-right:1px solid silver;border-bottom:1px solid silver;width:100%"><tr>';

				//Get the first row number
				var rowNumber = mvrs.details[0].row;

				//get column headers
				mvrs.details.forEach(function(thisEntry){
					if(thisEntry.row == rowNumber){
						htmlTable+= '<td style="padding:10px !important;border-left:1px solid silver;border-top:1px solid silver;background-color:WhiteSmoke;">'+thisEntry.question+'</td>';
					}
				});
				
				rowNumber = '';
				
				//add each row
				mvrs.details.forEach(function(thisEntry){
					//insert a new row each time the row number changes
					if(thisEntry.row != rowNumber) htmlTable+= '</tr><tr>';
					//add each individual cell value (knowing it has been sorted correctly so they'll all be in order)
					htmlTable+= '<td style="padding:10px !important;border-left:1px solid silver;border-top:1px solid silver;">'+thisEntry.value+'</td>';
					rowNumber = thisEntry.row;
				});
 
				htmlTable+= '</tr></table></div>';
			}
		});

		jQuery('#element\\.sc_task\\.description').after(htmlTable);
	}
	
}
Brian36
Tera Explorer

I can verify that the solution still works in Rome.

DiNesh, did you remember to turn off the "isolate script" option on your client script?
You should also turn on "Client callable" on your script include.

Your code seems to otherwise be identical to Peter's. The only modifications I have done are the lines for "list collector" variable types, so it should work.

DiNesh77
Tera Contributor

@Brian 

@peter.cawdron.personal 

 

Hi Brian\Peter,

Thanks for the valuable suggestions and as u mentioned i forgot to uncheck the Isolate script in client script and it had cost me the problem.

Now it is working fine that i am able to insert a table which has the MRVS fields and values on the sc catalog task form.

But i wonder is there any option available to insert the table in the variables section of the  sc catalog task form ?.

picture:

find_real_file.png

Mike Lyttle
Giga Contributor

Hi Brian,

Updated the script include with your "list collector" code (in both places), but the MRVS list collector fields are still just displaying as a string of sys_ids, rather than display values. Are you able to confirm, and post your complete script please?

Thanks

Mike Lyttle
Giga Contributor

Hi Brian

Realised that your code doesn't go through the list collector array and return the displayValues. Currently your code would only work if there was 1 referenced record in the list collector, it would return just sys_ids if there were more than 1. Have updated the code, which now works.

//if this is a reference field get the display value
if (mrvsDefintion[thisVariable].type == 'Reference' && mrvsDefintion[thisVariable].table != '') {
    var getDisplayVal = new GlideRecord(mrvsDefintion[thisVariable].table);
    if (getDisplayVal.get(thisValue)) {
        thisValue = getDisplayVal.getDisplayValue();
    }
}
if (mrvsDefintion[thisVariable].type == 'List Collector' && mrvsDefintion[thisVariable].table != '') {
    lcArr = [];
    var getDisplayValLC = new GlideRecord(mrvsDefintion[thisVariable].table);
    getDisplayValLC.addEncodedQuery("sys_idIN" + thisValue);
    getDisplayValLC.query();
    while (getDisplayValLC.next()) {
        lcArr.push(getDisplayValLC.getDisplayValue().toString());
    }
    thisValue = lcArr;
}
Ramon Marteles
Tera Explorer

Great contribution from Peter, and the rest of you.

In case you use other languages than English you should change some lines in the code in the script include.
Don't ask for Display Value but for Value to check it it is a reference field, or other type of fields, otherwise you wont't display the right values

 

This would be the code to replace:

while(mrvsStructure.next()){
	//What is the title of this MRVS?
	if(title=='') title = mrvsStructure.variable_set.title.toString();
	//What about each of the variables
	//Note: type 'Reference'=8 ; type 'List Collector' = 21
	mrvsDefintion[mrvsStructure.name.toString()] = {"name" :    mrvsStructure.name.toString(),
													"question": mrvsStructure.question_text.toString(),
													"sys_id":   mrvsStructure.sys_id.toString(),
													"type":     mrvsStructure.type.getValue(),
													"table":    mrvsStructure.type.getValue()=="8" ? mrvsStructure.reference.getValue() : mrvsStructure.type.getValue()=="21" ? mrvsStructure.list_table.getValue() : "",
													"order":    mrvsStructure.order.toString(),
													"row":      "",
													"value":    ""};
}

 

And when asking for variables:

//if this is a reference field get the display value
//Note: type 'Reference'=8 ; type 'List Collector' = 21
if((mrvsDefintion[thisVariable].type=='8' || mrvsDefintion[thisVariable].type=='21') && mrvsDefintion[thisVariable].table!=''){
	var getDisplayVal = new GlideRecord(mrvsDefintion[thisVariable].table);
	if(getDisplayVal.get(thisValue)){
		thisValue = getDisplayVal.getDisplayValue();
	}
}


//If this is a select box with choices, get the question_choice (display value)
//Note: type 'Select Box'=5
if(mrvsDefintion[thisVariable].type=='5'){

	var getQuestionChoice = new GlideRecord('question_choice');
	getQuestionChoice.addEncodedQuery('question='+ mrvsDefintion[thisVariable].sys_id +'^value=' + thisValue);
	getQuestionChoice.query();
	if(getQuestionChoice.next()){
		thisValue = getQuestionChoice.text.toString();
	}
}

 

Brian_ZB
Tera Explorer

Thank you for correcting this Mike.
I'll admit that this particular scenario was not tested as List collector variables in MRVS is not that common in our environment as of yet.

Adam43
Tera Contributor

would this display solution work on Now Agent since MRVS do not display on mobile?  are the fields editable inside this new display option?

Claudio6
Tera Expert

AWESOME! Thanks for sharing! You're my hero!

RandyH
Tera Explorer

Copied into a Vancouver instance.  Works as advertised across our sc_task records impacted by MRVSs. No additional effort required.  Very sustainable - excepting future JQuery prohibitions.

Arpita Patnaik
Tera Contributor

Hi @petercawdron In my case I have some variables in the mrvs which are not always visible. They get visible if a certain variable is set as 'yes'. How can I hide the empty variables from displaying ?

 

Thanks in Advance!

Version history
Last update:
‎02-24-2020 08:55 PM
Updated by: