Script include is not working properly

satya30
Tera Contributor

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: 

gs.info("check if it is checking for property: " +prop, +answer); - till here it is working properly
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

	}
}



7 REPLIES 7

abhi159
Kilo Sage

@satya30 In line var answer =JSON.parse(answer);  in client script update this with

var answer=JSON.parse(response);

Please mark this response as correct or helpful if it assisted you with your question.

satya30
Tera Contributor

I my server side script include, logs are not coming. 
Log in the loop is also not coming

		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;
    },



 

Mohan raj
Mega Sage

Hi @satya30,

 

You have comment severside call to get response for script, uncomment the below line in the on change client script.

 

var answer = response.responseXML.documentElement.getAttribute("answer");

 

and try below script 

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 severRes = JSON.parse(answer);
        g_form.setValue("property_info_name", severRes .name);
        g_form.setValue("property_info_state", severRes .state);
        g_form.setValue("property_info_country", severRes .country_name);
        g_form.setValue("property_info_phone", severRes .phone);
        g_form.setValue("property_info_email", severRes .email);
        g_form.setValue("property_info_area_director", severRes .area_director);
        g_form.setValue("property_info_rvp", severRes .rvp);

        if (g_form.getValue("internal_user") != "true") {
            g_form.setValue("contact_info_phone", severRes .phone);
            g_form.setValue("contact_info_email", severRes .email);
        }
    }

	}
}

 

 If my response helps you, please mark it as "Accept Solution" or hit the thumbs up to indicate it was helpful.

In my server side script, Logs itself aren't coming