Script include is not working properly
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-27-2025 12:16 AM
Script include is successfully receiving the values of sys id from client script but objects are not returning. Please help me on how to return correct values from script include. Thank you
Script include:
getPropertyData: function(sysId) {
var answer = {};
var prop = sysId || this.getParameter("sys_id");
gs.info("Script Include 'sn_customerservice.CHCSMUtilsv2' was called with property '" + prop + "'");
var pr = new GlideRecord("customer_account");
//pr.get(prop);
pr.addQuery('sys_id', prop);
pr.query();
if(pr.next())
{
gs.info("check if it is checking for property: " +prop, +answer);
answer.property_code = pr.number.toString();
answer.secondary_id = pr.u_secondary_id.getDisplayValue();
answer.name = pr.name.getDisplayValue();
answer.brand_code = pr.u_brand;
answer.brand_name = pr.u_brand.getDisplayValue();
answer.product_code = pr.u_brand_sub_class;
answer.product_name = pr.u_brand_sub_class.getDisplayValue();
answer.street = pr.street.toString();
answer.city = pr.city.getDisplayValue();
answer.state = pr.state.toString();
answer.postal_code = pr.zip.getDisplayValue();
answer.country_code = pr.country.getDisplayValue();
answer.country_name = pr.u_country_name.getDisplayValue();
answer.email = pr.u_email.getDisplayValue();
answer.phone = pr.phone.getDisplayValue();
answer.general_manager = pr.u_general_manager.toString();
answer.area_director = pr.u_area_director.toString();
answer.ar_dir = pr.u_area_director.getDisplayValue();
answer.rvp = pr.u_area_director.manager.toString();
answer.rvp1 = pr.u_area_director.manager.getDisplayValue();
answer.reservation_status_code = pr.u_reservation_status;
answer.reservation_status = pr.u_reservation_status.getDisplayValue();
answer.call_fwd = pr.u_call_forwarding_program.toString();
answer.call_fwd_mobile = pr.u_call_forwarding_mobile_program.toString();
answer.call_fwd_plus = pr.u_call_forwarding_plus_program.toString();
answer.contract_status_code = pr.u_effective_contract_status.getValue();
answer.u_guest_room_count = pr.u_guest_room_count.getValue();
gs.info("Loop is working correctly: " +answer);
}
gs.info("Script Include 'sn_customerservice.CHCSMUtilsv2' was called with property '" + prop + "', brand: " + answer.brand_name);
var result = JSON.stringify(answer);
//Debugger:
gs.info("Script Include 'sn_customerservice.CHCSMUtilsv2', function 'getPropertyData': Found " + pr.getRowCount() + " record using parameter '" + prop + "':: '" + result + "'");
return result;
},
Client Script: Here we need all those additional object values as it is being used in Many other items.
function onChange(control, oldValue, newValue, isLoading) {
if (newValue == '') {
return;
}
var ga = new GlideAjax("sn_customerservice.CHCSMUtilsv2");
ga.addParam("sysparm_name", "getPropertyData");
ga.addParam("sys_id", newValue);
ga.getXMLAnswer(setPropData);
function setPropData(response) {
if (response) {
// var answer = response.responseXML.documentElement.getAttribute("answer");
var answer = JSON.parse(answer);
g_form.setValue("property_info_name", answer.name);
g_form.setValue("property_info_state", answer.state);
g_form.setValue("property_info_country", answer.country_name);
g_form.setValue("property_info_phone", answer.phone);
g_form.setValue("property_info_email", answer.email);
g_form.setValue("property_info_area_director", answer.area_director);
g_form.setValue("property_info_rvp", answer.rvp);
if (g_form.getValue("internal_user") != "true") {
g_form.setValue("contact_info_phone", answer.phone);
g_form.setValue("contact_info_email", answer.email);
}
}
//Type appropriate comment here, and begin script below
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-27-2025 01:00 AM
Hi @satya30,
I try to test the script include by passing the sysId in Background script, get the log which mentioned. It working for me in Background script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-27-2025 01:11 AM
Hello,
If the "Loop is working correctly" line is not printed to the log then there's an issue somewhere in the lines of code that populate your "answer" object. Try wrapping those lines into a try ... catch block and check if an error is printed.
gs.info("check if it is checking for property: " +prop, +answer);
try {
answer.property_code = pr.number.toString();
// add all your other code that populates the "answer" object here
} catch (error) {
gs.error(error);
}
gs.info("Loop is working correctly: " +JSON.stringify(answer));
Regards,
Robert
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-27-2025 01:13 AM - edited 03-27-2025 01:14 AM
Hello @satya30, can you please try to call your SI using Background script and verify whether you see log statements are printed? If its working fine there, then enable the Standbox checkbox there on the Script Include if you are in Xanadu or higher.
Refer:
Regards,
Nishant