GlideAjax best example to get data from Server side to client side ServiceNow
Client Script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
// return;
}
if (g_form.isNewRecord() && newValue != undefined && newValue != "") {
var ga = new GlideAjax('sn_customerservice.getParentData');
ga.addParam('sysparm_name', 'getData');
ga.addParam('sysparm_parent', newValue); // When you want to pass a value
ga.getXMLAnswer(getDataParent);
}
function getDataParent(answer) {
var ans = answer.split(",");
g_form.setValue("u_customer_name", ans[0]);
g_form.setValue("u_contract_number", ans[1]);
}
}
Script Include
var getParentData = Class.create();
getParentData.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
getData: function() {
var obj = '';
var gr = new GlideRecord("sn_customerservice_flex_financial_case");
if (gr.get(this.getParameter('sysparm_parent'))) {
obj = gr.u_customer_name.getDisplayValue() + "," + gr.u_contract_number.getDisplayValue();
}
return obj;
},
type: 'getParentData'
});
GlideAjax example to get Data from Server side to Client Side ServiceNow
Working Code Asked question August 9, 2023
Sorry, you do not have permission to read comments.