How to auto-populate Multi-Row Variable Set?

MarioP1
Tera Contributor

Hello Community,

What is the best approach to auto-populate fields on 'Multi-Row Variable Set' based on 'OnChange' of reference variable on catalog item?

For example:  Lets say User has selected following value on reference variable on catalog item:

find_real_file.png

Now the above selected value needs to be auto-populated on multi-row variable set below:

find_real_file.png

Please advise the best way to achieve this.

Thanks

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@MarioP 

you can create onChange Client Script on that Reference variable and set the JSON string of the MRVS

I have shared solution here; adding to this post as well

How to populate Requestor Details in variables of MRVS?

Sample Script Below:

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

    listcollector:function() {    

        var listValuename = [];
        var userInfo = this.getParameter('sysparm_user_info');
        var query = 'sys_idIN' + userInfo;
        if(userInfo)
        {            
            var gr = new GlideRecord('sys_user');
            gr.addEncodedQuery(query);
            gr.query();
            if(gr.next()){
                
                listValuename.push({
                    "name": gr.getValue('name'), 
                    "title": gr.getValue('title')
                });
            }
        }
        gs.info('ARB JSON'+JSON.stringify(listValuename));
        return JSON.stringify(listValuename);
    },
    type: 'populateEmailfromList'

});

onChange Client Script:

function onChange(control, oldValue, newValue, isLoading) {
	if (isLoading) {
		return;
	}

	if(newValue == ''){
		g_form.clearValue('mrvsVariableName'); // give name of MRVS variable set here
	}

	if(oldValue != newValue){
		var ga = new GlideAjax('populateEmailfromList'); 
		ga.addParam('sysparm_name', 'listcollector');
		ga.addParam('sysparm_user_info', g_form.getValue('requestor')); // give here the requestor variable name
		ga.getXML(listcolleValues);

		function listcolleValues(response) {
			var val = response.responseXML.documentElement.getAttribute("answer");
			g_form.setValue('mrvsVariableName', val);  // give name of MRVS variable set here
		}
	}
}

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

14 REPLIES 14

Dash2
ServiceNow Employee
ServiceNow Employee

@Ankur Bawiskar  The "name" and "title" in the script include, are those the variable names or the field names from the user table? 

 

Thank you

those are name of variables present under MRVS

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi @Ankur Bawiskar 

How would I do this with Locations? I also have a List collector that i need populated?

 

.

 

The Variable is named "company_market" and references the cmn_location table where type=market

 

The multirow variable set has 3 variables

"market_name" - this also references the cmn_location table and i would like it to add all the active locations where the "company_market" selected is the parent value. Once this is loaded i have 2 fields that i would like to load for each line item as well.

"ad" - this would reference the "Contact" field for the location 

"list" and a list collector that would load all the locations that are active and have the same contact.

 

Here is an image of what i have on the Portal and how it would look. I am not sure how to get the line items to be added automatically.

 

DillinBradley_0-1673987447037.png

 

 

I would like some help, I have a Record Producer "Form" where inside it I have a multi-row variable, I created another Reord Producer "Form" and created another multi-row, I wanted to know if there is a way to automatically copy the information from the first multi-row to another in forms that have the second multi-row, there are some scripts that allow me to copy the same information from one multirow variable to another?

Praseena
Tera Contributor

Hello all, I tried the same and the MVRS populates rows with empty values . Could someone help me with it? Has anyone faced this situation?