Hiding the variables of catalog item in portal based on requested email

Radhika devi
Tera Contributor

i want to hide few checkboxes on portal page of a catalog item based on requested by email variable

example: if requested by email ends with path.us then show only few boxes, hide remaining boxes

i tried creating UI policies and client scripts but no use, can anyone help in this regard please...

1 ACCEPTED SOLUTION

@Radhika devi Could you please try the following and let me know if it works.

 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading) return;
    g_form.getReference('requested_by_email', function(requestedBy) {
        if (requestedBy && great_plains == 'true') {
            if (requestedBy.email.endsWith("wellpath.us")) {
                g_form.setDisplay('corp_director_of_accounting', true);
                g_form.setDisplay('corp_sub_senior_accountant', true);
            }
        } else {
            g_form.setDisplay('corp_director_of_accounting', false);
            g_form.setDisplay('corp_sub_senior_accountant', false);
        }
});
}

View solution in original post

17 REPLIES 17

Still not working, it is showing all checkboxes when great plains is checked

Radhikadevi_0-1744803540398.png

 

Radhikadevi_1-1744803589432.png

 

Radhikadevi_2-1744803625151.png

Don't know where it is going wrong, troubling me since 3 days. Thanks for your all responses and suggestions..

Hi @Radhika devi 

Create one single line text variable to store the email id of the requested by. You can hide that variable.

Then use UI policy on that hidden variable.

 

Regards,

Siva

@Radhika devi 

try this

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading) return;
    g_form.getReference('requested_by_email', function(requestedBy) {
        if (requestedBy && g_form.getValue('great_plains').toString == 'true') {
            if (requestedBy.email.toString().endsWith("wellpath.us")) {
                g_form.setDisplay('corp_director_of_accounting', true);
                g_form.setDisplay('corp_sub_senior_accountant', true);
            }
        } else {
            g_form.setDisplay('corp_director_of_accounting', false);
            g_form.setDisplay('corp_sub_senior_accountant', false);
        }
    });
}

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

Hi @Ankur Bawiskar ,

Tried above script but still it is showing all options instead of only 2 which are mentioned in the script. Thank you for your responses and it Iooks like a simple requirement but troubling me since 3 days..

@Sandeep Rajput--Thank you so much for the assistance in providing the solution for requirement. It was great learning for me and appreciate your efforts in continuous follow up in providing solution. The below script suggested by you helped me in completing the requirement. Once again thank you for the assistance.
 
function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading) return;
    var great_plains_access = g_form.getValue('great_plains');
    if (newValue.includes("Wellpath.us") && great_plains_access == 'true') {
        g_form.setDisplay('corp_director_of_accounting', true);
        g_form.setDisplay('corp_sub_senior_accountant', true);
        g_form.setDisplay('corp_senior_accountant', false);
        alert('inside second if');
    } else {
        g_form.setDisplay('corp_director_of_accounting', false);
        g_form.setDisplay('corp_sub_senior_accountant', false);
        g_form.setDisplay('corp_senior_accountant', true);
    }
}
//Type appropriate comment here, and begin script below