Prevent a request being raised if the user has either no manager set or the manager is inactive

wiganmichae
Tera Contributor

We have an issue with some user provisioning for the user's manager.  Until we find a fix we want to avoid issues with items auto approving so want to prevent any user who manager field is either empty of the manager in their is inactive to not be able to raise a request.

Ideally one step to do this would be good but we could say to do a scheduled task each day to remove inactive managers from any user's and then have another step for stopping anyone with an empty manager from raising a request.

Any help would be greatly appreciated.

1 ACCEPTED SOLUTION

@wiganmichae 

there is small correction in my script, I updated it above

sharing here as well

gr.addQuery("sys_id", user_id); // it should be sys_id and not sys+id

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

12 REPLIES 12

Ankur Bawiskar
Tera Patron
Tera Patron

@wiganmichae 

you can hide the catalog item itself for those users so that they don't see in portal and don't submit, rather than showing them and then stopping the submission

You can use User Criteria for this and use advanced script

Then add that User Criteria in "Available For" related list on that catalog item

var gr = new GlideRecord("sys_user");
gr.addQuery("sys_id", user_id);
gr.query();
if (gr.next()) {
    if (gr.manager.toString() == '' || gr.manager.active.toString() == 'false')
        answer = false;
    else
        answer = true;
}

1) click New in the related list of Available for

AnkurBawiskar_0-1746765934529.png

 

2) something like this

AnkurBawiskar_1-1746766002488.png

 

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

@wiganmichae 

Hope you are doing good.

Did my reply answer your question?

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,

I'm still testing it at the moment and it works at first glance but then tried someone who should work and they were being restricted also.

@wiganmichae 

is there any User Criteria added in "Not available for" related list?

share some more details.

The script I shared should work fine if there is nothing added in "Not available for" related list.

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