The CreatorCon Call for Content is officially open! Get started here.

Hide catalog variable if logged in user has “Is Manager” as true

Dee123
Tera Contributor

Trying to design a catalog form where if the it checks the logged in user - and if that user’s “Is Manager” property = true, then one of the attachment variable that required for manager approval is hidden.

 

From what I’ve found online this needs to be done as client script instead of catalog UI policy - is that correct? I’m having trouble scripting this one and would be grateful for any ideas. Thanks!

2 ACCEPTED SOLUTIONS

ChallaR
Mega Guru

Hi @Dee123 ,

 

you can create a catalog client script  please follow below steps  -

 

  • Name: Hide Manager Attachment
  • Catalog Item: Select your item
  • UI Type: All or Desktop
  • Type: onLoad

 

function onLoad() {
    // Get the logged-in user's sys_id
    var userSysId = g_user.userID;

    // Call a GlideAjax script to check if the user is a manager
    var ga = new GlideAjax('CheckIfManager');
    ga.addParam('sysparm_name', 'isUserManager');
    ga.addParam('sysparm_user_id', userSysId);
    ga.getXMLAnswer(function(response) {
        var isManager = response;

        if (isManager == 'true') {
            // Hide the attachment variable (replace 'attachment_variable_name' with actual name)
            g_form.setDisplay('attachment_variable_name', false);
        }
    });
}

 Please mark it as complete if this resolved your query and close the thread .

 

Thanks,

Rithika.ch

View solution in original post

Ankur Bawiskar
Tera Patron
Tera Patron

@Dee123 

it's an easy requirement with onLoad catalog client script + GlideAjax

what did you start with and where are you stuck?

GlideAjax Example Cheat Sheet (UPDATED) 

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

View solution in original post

9 REPLIES 9

Dee123
Tera Contributor

@ChallaR I used exactly the same script you provided - only changed the variable name for 'attachment_variable_name' 🙂 It appears the error was due to 'CheckIfManager' being called when it did not exist in my instance.

I was able to find a purely client-side solution that does not involve a script include 🙂 Thanks again for your time, will close this thread now.



@Dee123 Happy to help , your welcome 😄

Ankur Bawiskar
Tera Patron
Tera Patron

@Dee123 

it's an easy requirement with onLoad catalog client script + GlideAjax

what did you start with and where are you stuck?

GlideAjax Example Cheat Sheet (UPDATED) 

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 - I was able to find a purely client-side solution that does not involve a GlideAjax script 🙂 Thanks again for your time, will close this thread now.

@Dee123 

Thank you for marking my response as helpful.

As per new community feature you can mark multiple responses as correct.

If my response helped please mark it correct as well so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader