- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-04-2021 10:29 PM
Hi All,
I Have a List type variable on Catalog form, referring to user table. And I have MRVS on the same form, with the variables like name, email, department, telephone. If I select any user in List Type Variable, I need to populate the user related information in MRVS, like his name, email, location, telephone. And If I remove user from List Variable, related row needs to be deleted from MRVS. The same should work on MRVS too, like if i remove row from MRVS, the related user should be removed from List variable.
Thanks in Advance
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-05-2021 01:48 AM
Hi,
I assume your onChange is written on the Attendee List field
Updated below
Script Include:
var populateEmailfromList = Class.create();
populateEmailfromList.prototype = Object.extendsObject(AbstractAjaxProcessor, {
listcollector:function() {
var listValuename = [];
var userInfo = this.getParameter('sysparm_user_info'); //Passing the selected list collector asset value.
var query = 'sys_idIN' + userInfo;
if(userInfo)
{
var gr = new GlideRecord('sys_user');
gr.addEncodedQuery(query);
gr.query();
while (gr.next()){
//Push selected list collector values into multi row variable set variables.
// use the correct mrvs variable name here for attendee_name,email_address,department
listValuename.push({
"attendee_name": gr.getValue('sys_id'),
"email_address": gr.getValue('email'),
"department":gr.getDisplayValue('department')
});
}
}
return JSON.stringify(listValuename);
},
type: 'populateEmailfromList'
});
Client Script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var listValuename = g_form.getValue('attendees'); //Getting the list collector values.
var ga = new GlideAjax('populateEmailfromList'); //Calling Script Include.
ga.addParam('sysparm_name', 'listcollector'); // Function name of the script include.
ga.addParam('sysparm_user_info', listValuename); // Passing selected list collector value as parameter.
ga.getXML(listcolleValues);
function listcolleValues(response){
var val = response.responseXML.documentElement.getAttribute("answer");
g_form.setValue('variables.attendees_information', val); //Set multi row variable set with the selected list collector values.
}
}
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
‎02-04-2021 11:46 PM
You need to use onChange client script and get the JSON by passing the list values
refer below link for script help
Why to have this logic -> if MRVS row is removed then remove the user from list. You cannot have onChange catalog client script on MRVS variable. So this won't work
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
‎02-04-2021 11:59 PM
Hi Ankur, is there any way to check whether the users in List field are in MRVS or not. If user is there in List and not MRVS can we make any alert? the length doesnot work here because we are allowing users to add rows manually into MRVS, so we need another way to check whether the user in List is present in MRVS or not? if not get alert.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-05-2021 01:12 AM
Hi,
yes you can parse the JSON and check but this would be easier.
Update the MRVS directly based on the list users rather than checking which is present and absent
Also if you already have some JSON data in the MRVS then you can append the users by forming the complete json again
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
‎02-05-2021 01:22 AM
Thanks Ankur,
Update the MRVS directly based on the list users rather than checking which is present and absent:
But we are also allowing users to add user data manually, who are not in list variable. So, MRVS contains combination of rows copied from list values and manually entered values.
I am not good with JSON, could you please provide script?
I have written below SI and onChange for copying values from List to MRVS.
Script include:
var populateEmailfromList = Class.create();
populateEmailfromList.prototype = Object.extendsObject(AbstractAjaxProcessor, {
listcollector:function() {
var val=0;
var listValuename = [];
var userInfo = this.getParameter('sysparm_user_info'); //Passing the selected list collector asset value.
var query = 'sys_idIN'+userInfo;
if(userInfo)
{
var gr = new GlideRecord('sys_user');
gr.addEncodedQuery(query);
gr.query();
while (gr.next()){
//Push selected list collector values into multi row variable set variables.
listValuename.push({
"attendee_name": gr.getValue('sys_id'),
"email_address": gr.getValue('email'),
"department":gr.getDisplayValue('department')
});
}
}
val = JSON.stringify(listValuename);
return val;
},
type: 'populateEmailfromList'
});
onChange:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var listValuename = g_form.getValue('attendees'); //Getting the list collector values.
var ga = new GlideAjax('populateEmailfromList'); //Calling Script Include.
ga.addParam('sysparm_name', 'listcollector'); // Function name of the script include.
ga.addParam('sysparm_user_info', listValuename); // Passing selected list collector value as parameter.
ga.getXML(listcolleValues);
function listcolleValues(response){
var val = response.responseXML.documentElement.getAttribute("answer");
g_form.setValue('attendees_information',val); //Set multi row variable set with the selected list collector values.
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-05-2021 01:48 AM
Hi,
I assume your onChange is written on the Attendee List field
Updated below
Script Include:
var populateEmailfromList = Class.create();
populateEmailfromList.prototype = Object.extendsObject(AbstractAjaxProcessor, {
listcollector:function() {
var listValuename = [];
var userInfo = this.getParameter('sysparm_user_info'); //Passing the selected list collector asset value.
var query = 'sys_idIN' + userInfo;
if(userInfo)
{
var gr = new GlideRecord('sys_user');
gr.addEncodedQuery(query);
gr.query();
while (gr.next()){
//Push selected list collector values into multi row variable set variables.
// use the correct mrvs variable name here for attendee_name,email_address,department
listValuename.push({
"attendee_name": gr.getValue('sys_id'),
"email_address": gr.getValue('email'),
"department":gr.getDisplayValue('department')
});
}
}
return JSON.stringify(listValuename);
},
type: 'populateEmailfromList'
});
Client Script:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var listValuename = g_form.getValue('attendees'); //Getting the list collector values.
var ga = new GlideAjax('populateEmailfromList'); //Calling Script Include.
ga.addParam('sysparm_name', 'listcollector'); // Function name of the script include.
ga.addParam('sysparm_user_info', listValuename); // Passing selected list collector value as parameter.
ga.getXML(listcolleValues);
function listcolleValues(response){
var val = response.responseXML.documentElement.getAttribute("answer");
g_form.setValue('variables.attendees_information', val); //Set multi row variable set with the selected list collector values.
}
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader