How to hide one field based on the user's Location?

Ramu6
Tera Contributor

Hi All,

I  have a requirement that basically i have one record producer, in that i have one variable set, in that , three fields, "subject person, leave type and period", , so my requirement was that the field 'leave type' was only visible , when the users with location (WA or SA),

 

So please help me to achieve this

 

Thanks

Ramu

10 REPLIES 10

You can place the alert(info); before if logic and check what values your getting.

Regards
Harish

Ramu6
Tera Contributor

@Harish KM 

i put the alert , so its getting "null " value only, basically here i want to check the "state" of the location

i have tried user.location.state

Share your script include and client scripts  code

Regards
Harish

Ramu6
Tera Contributor

@Harish KM 

Script include

var Locationbased = Class.create();
Locationbased.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
           // initialize: function() {},
            getLocation: function() {
                var userID = this.getParameter('sysparm_user'); /
                var returnID = '';
                var user = new GlideRecord('sys_user');
                user.addQuery('sys_id', userID);
                user.query();
                if(user.next()) {
                    returnID = user.location.state;
                    
                }
                return returnID;
            },
            type: 'Locationbased'
        });
 
Client script
 
function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }

    //Type appropriate comment here, and begin script below
    var ga = new GlideAjax('Locationbased'); 
    ga.addParam('sysparm_name''getLocation'); 
    ga.addParam('sysparm_user', newValue); 
    ga.getXML(getInfo);

    function getInfo(response) {
        var info = response.responseXML.documentElement.getAttribute('answer');
        alert(info);
        if (info == 'WA' || info == 'TN')
            g_form.setDisplay('cash_out_period',true);

        else {
            g_form.setDisplay('cash_out_period',false);
        }

    }
}

Hi, Please add the logs like below and see what is happening and also ensure there is valid value in location's state field,

 

getLocation: function() {
var userID = this.getParameter('sysparm_user');
gs.info("userID==>"+UserID); // check in log if this is valid UserID
var returnID = '';
var user = new GlideRecord('sys_user');
user.addQuery('sys_id', userID);
user.query();
if(user.next()) {
returnID = user.location.state;
gs.info("returnID==>"+returnID); // check in log if there is a state value present, if null check location table

}
return returnID;
},
type: 'Locationbased'
});

Regards
Harish