I'm working on client script which reads data from alm_hardware table and reads also value from field u_invoice_date and that value is displayed in form field called invoice_date.
This script works fine, but I found one problem: when u_invoice_date field is not filled in asset by asset manager in form for specific devices, the output is blank. Working script bellow:
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading) {
return;
}
if (newValue == '') {
g_form.setValue("invoice_date", "");
return;
}
var reqVarHelper = new GlideAjax('x_swea2_wies_servi.WPCatalogItemClientHelpers');
reqVarHelper.addParam('sysparm_name', 'getRecord');
reqVarHelper.addParam("sysparm_table", "alm_hardware");
reqVarHelper.addParam("sysparm_query", "sys_id=" + g_form.getValue("select_device"));
reqVarHelper.addParam("sysparm_fields", "name,u_invoice_date");
reqVarHelper.getXML(function(response) {
var result = JSON.parse(response.responseXML.documentElement.getAttribute("answer"));
g_form.setValue("invoice_date", result.u_invoice_date);
});
}
Then I found table fm_expense_line and field date which is always field, therefore there is chance the form will have some value there always.
I started to modify legacy script with replacing table and field in script but it does not work, do you see any issues in bellow script?
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading) {
return;
}
if (newValue == '') {
g_form.setValue("invoice_date", "");
return;
}
var reqVarHelper = new GlideAjax('x_swea2_wies_servi.WPCatalogItemClientHelpers');
reqVarHelper.addParam('sysparm_name', 'getRecord');
reqVarHelper.addParam("sysparm_table", "fm_expense_line");
reqVarHelper.addParam("sysparm_query", "sys_id=" + g_form.getValue("select_device"));
reqVarHelper.addParam("sysparm_fields", "name,date");
reqVarHelper.getXML(function(response) {
var result = JSON.parse(response.responseXML.documentElement.getAttribute("answer"));
g_form.setValue("invoice_date", result.date);
});
}
Checked in browser console, there where no errors related to this topic. Any ideas, why it does not work in new script?
I have tried to remove JSON part from script and replacing it with console.log but could be I have made mistake there as well, therefore reverted back to version which is added in post.