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

Hi @Sandeep Rajput 

 

I tried creating the above catalog client script but its not working as expected. Please suggest any alternative way. Here is the way which I tried

 

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);
        }
});
}

@Radhika devi 

what came in alert?

add and share

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading)
        return;

    g_form.getReference('requested_by_email', function(requestedBy) {
        if (requestedBy && great_plains === 'true') {
            alert('inside if');
            if (requestedBy.email.toString().endsWith("wellpath.us")) {
                alert('inside email');
                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

@Radhika devi Could you please share more details on great_plains variable? is it a checkbox?

Yes , it is a checkbox. Please find below snapshots

 

Radhikadevi_0-1744743177789.png

 

Radhikadevi_1-1744743236086.png

 

Radhikadevi_2-1744743748741.png

 

Radhikadevi_3-1744743861458.png

 

 

Radhikadevi_4-1744743928845.png

 

I tried both UI policy and client script but still no change in output. Please help me in this regard

@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);
        }
});
}