
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-05-2021 05:46 AM
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:
Now the above selected value needs to be auto-populated on multi-row variable set below:
Please advise the best way to achieve this.
Thanks
Solved! Go to Solution.
- Labels:
-
User Interface (UI)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-05-2021 06:10 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-05-2021 05:53 AM
Hi,
Kindly refer to these links below. These might help you.
Thanks
Hemant
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-05-2021 05:55 AM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-05-2021 06:07 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-05-2021 06:10 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader