The Zurich release has arrived! Interested in new features and functionalities? Click here for more

Adding an additional property in AJAX

0890KM
Tera Contributor

Hey All, 

 

I have a quick question.  I have a onChange Client Script, that calls a script include with a property function. 

 

Here's the function within the script include: 

getPropertyValue : function(){
		var property = this.getParameter('sysparm_propertyName');
		var propertyValue = gs.getProperty(property);
		return propertyValue;

	


},

    type: 'ClientSideUtil'
});

 

 

This is the client script, I want to add another sys_property, but I am having an issue that the other property isn't working. Here's the code. 

function onChange(control, oldValue, newValue, isLoading) {
    // if (isLoading || !newValue) {
    //     // Clear decorations if the field is empty or loading
    //     g_form.removeDecoration('caller_id', 'icon');
    //     g_form.removeDecoration('caller_id', 'text-color');
    //     return;
    // }

    g_form.getReference('caller_id', vipCallerCallback);
}

function vipCallerCallback(caller) {
    if (!caller)
        return;

    var ga = new GlideAjax('global.ClientSideUtil');
    ga.addParam('sysparm_name', 'getPropertyValue');
    ga.addParam('sysparm_propertyName', "Sys_ID.sys_user_group.L2-Field Support");

    ga.getXMLAnswer(function(atlantaID) {
        // Remove any previous decorations
        g_form.removeDecoration('caller_id', 'icon-star', 'Field Support User', "color-green");
        g_form.removeDecoration('opened_for', 'icon-star', 'VIP User', 'color-red');

        // VIP Status
        if (caller.vip == 'true') {
            g_form.addDecoration('caller_id', 'icon-star', 'VIP User', 'color-red');
        }
        // Campus Group + not VIP
        if (caller.u_campus_group == atlantaID) {
            g_form.addDecoration('caller_id', 'icon-star', 'Field Support User', "color-green");
        }





    });
 var ga2 = new GlideAjax('global.ClientSideUtil');
    ga2.addParam('sysparm_name', 'getPropertyValue');
    ga2.ga.addParam('sysparm_propertyName', "Sys_ID.sys_user_group.L2-EP-Client Support");

    ga2.getXMLAnswer(function(secondGroupID) {
        g_form.removeDecoration('caller_id', 'icon-star', 'Field Support User', "color-green");
        g_form.removeDecoration('opened_for', 'icon-star', 'VIP User', 'color-red');


        if (caller.u_campus_group == secondGroupID) {
            g_form.addDecoration('caller_id', 'icon-star', 'EP Client Support', "color-blue");
        }

	

    });





}
1 ACCEPTED SOLUTION

dgarad
Giga Sage

Hi @0890KM 

change you code  as per below

var ga2 = new GlideAjax('global.ClientSideUtil');
    ga2.addParam('sysparm_name', 'getPropertyValue');
    ga2.addParam('sysparm_propertyName', "Sys_ID.sys_user_group.L2-EP-Client Support");

    ga2.getXMLAnswer(function(secondGroupID) {
        g_form.removeDecoration('caller_id', 'icon-star', 'Field Support User', "color-green");
        g_form.removeDecoration('opened_for', 'icon-star', 'VIP User', 'color-red');


        if (caller.u_campus_group == secondGroupID) {
            g_form.addDecoration('caller_id', 'icon-star', 'EP Client Support', "color-blue");
        }

	

    });
If my answer finds you well, helpful, and related to the question asked. Please mark it as correct and helpful.

Thanks
dgarad

View solution in original post

9 REPLIES 9

I see you have a type'o in this line

ga2.ga.addParam('sysparm_propertyName', "Sys_ID.sys_user_group.L2-EP-Client Support");

you have ga2.go.addParam, it looks like it should be just ga2.addParam.

 

Can you share error screenshot.

If my answer finds you well, helpful, and related to the question asked. Please mark it as correct and helpful.

Thanks
dgarad

dgarad
Giga Sage

Hi @0890KM 

change you code  as per below

var ga2 = new GlideAjax('global.ClientSideUtil');
    ga2.addParam('sysparm_name', 'getPropertyValue');
    ga2.addParam('sysparm_propertyName', "Sys_ID.sys_user_group.L2-EP-Client Support");

    ga2.getXMLAnswer(function(secondGroupID) {
        g_form.removeDecoration('caller_id', 'icon-star', 'Field Support User', "color-green");
        g_form.removeDecoration('opened_for', 'icon-star', 'VIP User', 'color-red');


        if (caller.u_campus_group == secondGroupID) {
            g_form.addDecoration('caller_id', 'icon-star', 'EP Client Support', "color-blue");
        }

	

    });
If my answer finds you well, helpful, and related to the question asked. Please mark it as correct and helpful.

Thanks
dgarad

Ankur Bawiskar
Tera Patron
Tera Patron

@0890KM 

what are you trying to send?

what's the use of sending the property name from GlideAjax when you can directly get the value in server side?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Bert_c1
Kilo Patron

I tried your client script code, once I got it to run, I got the same error. I suggest a restructure as follows:

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }

   //Type appropriate comment here, and begin script below
	var callerID = g_form.getValue('caller_id');
	alert('client script is running, callerID = ' +callerID);
//   	g_form.getReference('caller_id', vipCallerCallback);
	vipCallerCallback(callerID);
}

function vipCallerCallback(caller) {
    if (!caller)
        return;

    var ga = new GlideAjax('ClientSideUtil');
    ga.addParam('sysparm_name', 'getPropertyValue');
    ga.addParam('sysparm_propertyName1', "Sys_ID.sys_user_group.L2-Field Support");
    ga.addParam('sysparm_propertyName2', "Sys_ID.sys_user_group.L2-EP-Client Support");
	alert('vipCallCallback:  caller = ' + caller + '.');

    ga.getXMLAnswer(getResponse);
}
function getResponse(response) {
    // Remove any previous decorations
    g_form.removeDecoration('caller_id', 'icon-star', 'Field Support User', "color-green");
    g_form.removeDecoration('opened_for', 'icon-star', 'VIP User', 'color-red');
	alert('response = ' + response);
    // VIP Status
	alert('vipCallCallback: caller.vip = ' + caller.vip);
    if (caller.vip == 'true') {
        g_form.addDecoration('caller_id', 'icon-star', 'VIP User', 'color-red');
    }
        // Campus Group + not VIP
//        if (caller.u_campus_group == atlantaID) {
//            g_form.addDecoration('caller_id', 'icon-star', 'Field Support User', "color-green");
//        }
}

call the script include once:

var ClientSideUtil = Class.create();
ClientSideUtil.prototype = Object.extendsObject(AbstractAjaxProcessor, {

	getPropertyValue : function(){
		var property = this.getParameter('sysparm_propertyName1');
		var propertyValue1 = gs.getProperty(property);
		var property = this.getParameter('sysparm_propertyName2');
		var propertyValue2 = gs.getProperty(property);
		gs.info('ClientSideUtil: returning ' + propertyValue1 + ' and ' + propertyValue2);
		return propertyValue1+','+propertyValue2;
	},

    type: 'ClientSideUtil'
});

 

Your use of 

    ga.getXMLAnswer(function(atlantaID) {

and the second one seem wrong.  Also, referring to 'caller.vip' after the first call, and 'caller.u_campus_group' after the second makes no sense to me as I don't anything like those being set anywhere.