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

No nothing in the not Available for from memory.  I'm trying at the item and category level.

wiganmichae_0-1747024594175.png

 

@wiganmichae 

So the catalog item will be visible to these users

1) if logged in user has manager and is active

share your script here.

Did you test with the correct user?

Did you use User Criteria Diagnostics feature to see?

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

Here is the script

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;
}
 
 
I've tested with a user with no manager, inactive manager and they can't see the item.  But I've also tested with a user with correct active manager and they also can't see the item.

@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

I didn't even pick on that but would have cause the issue I was seeing for sure.  Working as expected not I just need to add to all the categories I want.