- 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 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 11:15 PM
Thank you so much for pointing and i did the following changes and it worked fine
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 JSON.stringify(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", returndata.Mrvs_Data);
}
}
} 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 07:36 AM
The response you are getting is correct so try like below line code:
g_form.setValue("mrvs_internal_name", answer);
or try as Hitoshi suggested.
Thanks,
Murthy
Murthy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-28-2022 07:38 AM
Before that the variable values should be the backend values of that variable
Murthy