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

DrewW
Mega Sage
Mega Sage

Did you make sure the new property exists and has a value?  If so do you have the case correct?

 

You may want to make this change in your getPropertyValue method

var propertyValue = gs.getProperty(property, "Property not found");

This way if the property does not exist you get something back telling you.

 

You also may want to consider updating getPropertyValue to allow you to send a comma delimited list of values so you do not have to make multiple calls to the server.

 

0890KM
Tera Contributor

yes, I created the new property with a value. It throws an error message when I add the new call. 

Ok, whats the error message?

 

0890KM
Tera Contributor