- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-27-2022 12:57 AM
Hello Guys,
We have a onchange client script written to automatically set the values of the catalog item onchange of "Quote" field and now we introduced the MRV's and we also need to automatically populate the values in the MRV based on the "Quote" value and i am thinking to create a seperate function in the script include and can we use 2 times the GlideAjax and call our seperate function and fill the MRV's data?
Please suggest me!!
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-28-2022 03:17 PM
So, in the script include, change to as follows. ServiceNow defaults field names to all lowercase.
obj["vendor"] = equipment.u_vendor+'';
obj["eqptype"] = equipment.u_equipment_type_model_no+'';
obj["quantity"] = equipment.u_quantity+'';
obj["racunt"] = equipment.u_rack_units+'';

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-28-2022 02:12 AM
As I've commented above, it's necessary to return an object and not a string in function getMRVData(). If string is going to be returned, it's necessary to JSON.parse() before setting the returned data.
Try to run the script to generate a list in Background script to make sure the script works as expected. The value to be returned should be an array.
I can check if Script Included used is posted here.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-28-2022 02:41 AM
Yes
script include:
getCustomerOrder: function() {
var results = {};
var Custorder = this.getParameter('sysparm_custOrd');
var gr = new GlideRecord('sn_ind_tmt_orm_order');
gr.addQuery('sys_id', Custorder);
gr.query();
if (gr.next()) {
results["opportunity_no"] = gr.u_opportunity + '';
results["svo_no"] = gr.u_quote_number + '';
results["Service_id"] = this.getCustomerOrderLine(Custorder, "Service ID") + '';
results["CSE_notes"] = this.getCustomerOrderLine(Custorder, "CSE comments") + '';
results["is_pm_required"] = this.getReferenceID('sn_ind_tmt_orm_order_line_item', 'u_is_pm_required', Custorder) + '';
results["MrvsData"] = this.getMRVData(Custorder)+'';
}
gs.log('JSON.stringify(results):'+JSON.stringify(results));
return JSON.stringify(results);
},
getMRVData: function(custOrder) {
var results = [];
var gr = new GlideRecord('sn_ind_tmt_orm_order');
gr.addQuery('sys_id', custOrder);
gr.query();
if (gr.next()) {
var orderLine = new GlideRecord('sn_ind_tmt_orm_order_line_item');
orderLine.addQuery('order', custOrder);
orderLine.query();
if (orderLine.next()) {
var orderLineItem = orderLine.sys_id;
var equipment = new GlideRecord('sn_ind_tmt_orm_equipments');
equipment.addQuery('u_customer_order_line_item1', orderLineItem);
equipment.query();
gs.log('row count:::'+equipment.getRowCount());
while (equipment.next()) {
var obj = {};
obj["Vendor"] = equipment.u_vendor+'';
obj["EqpType"] = equipment.u_equipment_type_model_no+'';
obj["Quantity"] = equipment.u_quantity+'';
obj["RacUnt"] = equipment.u_rack_units+'';
results.push(obj);
// gs.log('obj::'+obj);
}
}
}
return results;
},
client script
try {
//if(g_form.getValue('u_change_type')=='Update'){
// var ID = g_form.getDisplayBox('customer_order_no');
var ID = g_form.getValue('customer_order_no');
// alert(ID);
// var CustOrderID = getDisplayValue(ID);
var ga = new GlideAjax('ACUXValues');
ga.addParam('sysparm_name', 'getCustomerOrder');
ga.addParam('sysparm_custOrd', ID);
ga.getXML(populateDetails);
function populateDetails(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
if (answer) {
var returndata = JSON.parse(answer);
//alert(returndata);
if (g_form.getValue('type_of_change') == 'Technical Data Change') {
g_form.setValue("opportunity_id", returndata.opportunity_no);
function setQuote() {
g_form.setValue("svo", returndata.svo_no);
}
window.setTimeout(setQuote, 2500);
}
if (returndata.Service_id != '') {
g_form.setValue("service_id", returndata.Service_id);
}
if (returndata.CSE_notes != '') {
g_form.setValue("cse_notes", returndata.CSE_notes);
}
g_form.setValue("is_pm_required", returndata.is_pm_required);
g_form.setValue("list_of_equipment", JSON.stringify(returndata.MrvsData));
}
}
} catch (err) {
jslog('Bhavana A JavaScript runtime error occurred: ' + err.message);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-28-2022 04:46 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-28-2022 07:31 AM
If the values are showing up in the alert, the problem seems to be with the client script to set value to mrv. Try to directly set a static value to mrv. If this fails, check the mrv name to make sure it's 'list_of_equipment'. The name of mrv is the name that's displayed under "Variable set" in the form's Variable Sets tab.
g_form.setValue('list_of_equipment', JSON.stringify([{"Vendor":"test1","Eqptype":"test1","Quantity":"test1","RacUnt":"test1"}]));

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-28-2022 03:15 PM
One thing I noticed. Shouldn't field names be in lowercase? That is, "vendor", "eqptype", "quantity", "racunt".
1. Defined mrv as below.
2. Defined client script as below using all lowercase as field names.
g_form.setValue('list_of_equipment', JSON.stringify([{"vendor":"test1","eqptype":"test1","quantity":"test1","racunt":"test1"}]));
3. Execution result: