Info Needed

Abdul
Tera Contributor

Hi 

 

i would like to know how this scenario can be done.

I have a variable named "Expenditure type" and this expenditure type has a value named"Lease"

the "Lease" should be visible only for the users from the US. (i,e) when the user's email id ends with @usa.com 

 

Can you please help me with this

1 ACCEPTED SOLUTION

Chaitanya ILCR
Kilo Patron

Hi @Abdul ,

create this client callable script include

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

    isParklandUser: function() {

        var email = gs.getUser().getEmail();

        return email && email.endsWith('@usa.com');
    }

});

 

ChaitanyaILCR_1-1749203209124.png

you may see the highlighted field as Client callable ( check it )

 

create onload client script

 

function onLoad() {
    var expenditureType = 'u_expenditure_type'; //update this with expenditure type varialbe name if required
    var ga = new GlideAjax('CheckUserEmailDomain');
    ga.addParam('sysparm_name', 'isParklandUser');
    ga.getXMLAnswer(function(response) {
        if (response == 'true' || response == true)
            g_form.removeOption(expenditureType, 'lease'); // is lease is the backend value of lease choice else update it with correct value
    });

}

ChaitanyaILCR_2-1749203325606.png

update the variable names and choice values if required with correct values

 

 

Please mark my answer as helpful/correct if it resolves your query.

Regards,
Chaitanya

 

View solution in original post

7 REPLIES 7

Dr Atul G- LNG
Tera Patron
Tera Patron

yes you can write a client script and do the dot walk to location.

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

should i use script includes?

@Abdul,

Yes you'll want to make a script include for the server side actions.  You'll need to make it client callable and use GlideAjax in your client script.  You can then add/remove choices using g_form based on the result.

Abdul
Tera Contributor

Can you please correct my code

 

Script Include:

var CheckUserEmailDomain = Class.create();
CheckUserEmailDomain.prototype = {
    isParklandUser: function() {
        var email = gs.getUser().getEmail();
        if (email && email.toLowerCase().endsWith('@parklandusa.com')) {
            return 'true';
        }
        return 'false';
    },

    type: 'CheckUserEmailDomain'
};
 
 
Client Script:
 
function onLoad() {
    //Type appropriate comment here, and begin script below
    var ga = new GlideAjax('CheckUserEmailDomain');
    ga.addParam('sysparm_name', 'isParklandUser');
    ga.getXMLAnswer(function(answer) {
        var isParkland = answer === 'true';
        var expenditureType = g_form.getControl('u_expenditure_type');
        if (!expenditureType) return;

        var options = expenditureType.options;

        for (var i = options.length - 1; i >= 0; i--) {
            var option = options[i];
            if (option.value.toLowerCase() === 'lease' && !isParkland) {
                expenditureType.remove(i);
            }
        }
    });
}