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

vikas shukla
Kilo Guru

Hi,

you can use:

1.Client script(GlideAjax)+ script include

2.getReference

Both are good to auto populate the values into the field.

Please mark helpful.

Thanks,

Vikas

Prasad Pagar
Mega Sage

Hi,

This will exactly answer your question

http://rubenferrero.com/servicenow/multi-row-variable-set-form-communication/

Please mark my answer correct/helpful if applicable.

Thank you
Prasad

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