- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-01-2022 06:53 AM
Hello team 🙂
I have a catalog item with a multi row variable set (mrvs called contact). I need to populate 10 record from contact (customer_contact) table.I want to populate this MRVS onLoad.
I have built the following script include to get the data:
var getContactDataList = Class.create();
getContactDataList.prototype = Object.extendsObject(AbstractAjaxProcessor,{
getDataList: function() {
// setup variables
var query_param = this.getParameter('sysparm_query_param');
var array = [];
var result = '';
var gr = new GlideRecord('customer_contact');
gr.addQuery('first_name');
gr.query();
while(gr.next()){
// push selected values into array
array.push({
first_name: gr.getValue('first_name'),
email: gr.getValue('email'),
last_name: gr.getValue('last_name')
});
}
// store result in JSON formatted string
result = JSON.stringify(array);
return result;
},
type: 'getContactDataList'
});
I've created an onLoad client catalog script and associated it with the variable set "contact":
function onLoad() {
// call script include
var ga = new GlideAjax('getContactDataList');
// function to call
ga.addParam('sysparm_name', getDataList);
ga.getXML(updateDataList);
}
function updateDataList(response){
var val = response.responseXML.documentElement.getAttribute("answer");
// set mrvs with retrieved values
g_form.setValue('contact', val);
}
Nothing is being populated in the MRVS onLoad.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-01-2022 07:02 AM
Hi,
update as this
Script Include:
var getContactDataList = Class.create();
getContactDataList.prototype = Object.extendsObject(AbstractAjaxProcessor,{
getDataList: function() {
// setup variables
var array = [];
var gr = new GlideRecord('customer_contact');
gr.setLimit(10);
gr.query();
while(gr.next()){
// push selected values into array
array.push({
first_name: gr.getValue('first_name'),
email: gr.getValue('email'),
last_name: gr.getValue('last_name')
});
}
// store result in JSON formatted string
return JSON.stringify(array);
},
type: 'getContactDataList'
});
Client Script: Applies to Catalog Item and not Variable Set
function onLoad() {
// call script include
var ga = new GlideAjax('getContactDataList');
// function to call
ga.addParam('sysparm_name', 'getDataList');
ga.getXMLAnswer(updateDataList);
}
function updateDataList(response){
var answer = response;
g_form.setValue('contact', answer);
}
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
‎08-01-2022 07:00 AM
If the MRVS is blank, and you want to populate it when the Catalog Item, RITM, or Catalog Task loads, then your onLoad Catalog Client Script needs to be associated with the Catalog Item, not within the MRVS. As with all script troubleshooting, add alerts to your Client Script and gs.info, etc to your Script Include to ensure it's running, and to see how far it is getting, records returned, variables populated, etc.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-01-2022 07:02 AM
Hi,
update as this
Script Include:
var getContactDataList = Class.create();
getContactDataList.prototype = Object.extendsObject(AbstractAjaxProcessor,{
getDataList: function() {
// setup variables
var array = [];
var gr = new GlideRecord('customer_contact');
gr.setLimit(10);
gr.query();
while(gr.next()){
// push selected values into array
array.push({
first_name: gr.getValue('first_name'),
email: gr.getValue('email'),
last_name: gr.getValue('last_name')
});
}
// store result in JSON formatted string
return JSON.stringify(array);
},
type: 'getContactDataList'
});
Client Script: Applies to Catalog Item and not Variable Set
function onLoad() {
// call script include
var ga = new GlideAjax('getContactDataList');
// function to call
ga.addParam('sysparm_name', 'getDataList');
ga.getXMLAnswer(updateDataList);
}
function updateDataList(response){
var answer = response;
g_form.setValue('contact', answer);
}
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
‎08-01-2022 07:23 AM
Dear Ankur Bawiskar,
Thank for your quick reply.
i have tried what you mention above and still not getting the desired results
note: Applies to Catalog Item