Please correct my code

Abdul
Tera Contributor

Hi 

 

i am trying to hide an option of a record producer based on the user's email id.

If the user has domain usa then the user should see the option of a variable.

Anyone else apart form usa should not see this option.

i have used Script Include and Catalog Client script.

 

Despite this i am still able to see the option lease.

The variable Expenditure type is a Look up select box and the Expenditure comes from sys_choice table i have added the option there

 

Script Include: Client Callable is on

var CheckUserEmailDomain = Class.create();
CheckUserEmailDomain.prototype = {
    isParklandUser: function() {
        var email = gs.getUser().getEmail();

        if (email && email.endsWith('@parklandusa.com'))
        {
            return "usa";
            }

        else {
            return "other";
            }
    },

    type: 'CheckUserEmailDomain'
};
 
 
Client Script:
its Onload:
function onLoad() {
    var ga = new GlideAjax('CheckUserEmailDomain');
    ga.addParam('sysparm_name', 'isParklandUser');
    ga.getXMLAnswer(function(response) {
        var domain = response;
        g_form.removeOption('u_expenditure_type', 'lease');
        if (domain === 'usa') {
            g_form.addOption('u_expenditure_type', 'lease', 'Lease');
        }
    });


}
 
 
 
1 ACCEPTED SOLUTION

Chaitanya ILCR
Kilo Patron

Hi @Abdul ,

 

here is the updated version of scripts

script include (make sure the client callable checkbox is checked)

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

        return gs.getUser().getEmail().toLowerCase().includes('@parklandusa.com');

    },
    type: 'CheckUserEmailDomain'
});

ChaitanyaILCR_0-1749662869789.png

client script

 

function onLoad() {
    var ga = new GlideAjax('CheckUserEmailDomain');
    ga.addParam('sysparm_name', 'isParklandUser');
    ga.getXMLAnswer(function(response) {
        if (response == 'false' || response == false) {
            // g_form.addOption('u_expenditure_type', 'lease', 'Lease');
            g_form.removeOption('u_expenditure_type', 'lease');
        }
    });
}

 

 

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

Regards,
Chaitanya

 

View solution in original post

1 REPLY 1

Chaitanya ILCR
Kilo Patron

Hi @Abdul ,

 

here is the updated version of scripts

script include (make sure the client callable checkbox is checked)

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

        return gs.getUser().getEmail().toLowerCase().includes('@parklandusa.com');

    },
    type: 'CheckUserEmailDomain'
});

ChaitanyaILCR_0-1749662869789.png

client script

 

function onLoad() {
    var ga = new GlideAjax('CheckUserEmailDomain');
    ga.addParam('sysparm_name', 'isParklandUser');
    ga.getXMLAnswer(function(response) {
        if (response == 'false' || response == false) {
            // g_form.addOption('u_expenditure_type', 'lease', 'Lease');
            g_form.removeOption('u_expenditure_type', 'lease');
        }
    });
}

 

 

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

Regards,
Chaitanya