How to hide a Service Catalog Item based on the logged in user's company
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-17-2022 06:30 PM
Hi All,
Problem: We have users from multiple companies share our ServiceNow instance, because the support team is shared.
Recently we decided that few of the catalog items are not applicable to Company A as much as it does for Company B and Company C.
We would like to hide these catalog items just for users from Company A without making too many modifications. I am stuck here, and I am new to ServiceNow.
All help is much appreciated. Thank you!
I have already created a User Criteria.
I selected the company and added the new User Criteria. I added it to the Not Available For" on the catalog item.
Problem is: The user from company A is still able to see the catalog item under their Portal, but they get the error message that they are not authorized to access the record. How can I ensure the item is now shown to those users.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-17-2022 07:14 PM
Hi Sam,
You can use onload client script for this and glideAjax combination
Client Script:
function onLoad() {
// show by default
g_form.setVisible('u_regression', true);
//Type appropriate comment here, and begin script below
var ajax = new GlideAjax('getCompanyUser');
ajax.addParam('sysparm_name', 'getCompany');
ajax.getXML(callBackMethod);
}
function callBackMethod(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
if(answer == 'true'){
g_form.setVisible('u_regression', false); // hide if france
}
}
Script Include: It should be client callable
var getCompanyUser = Class.create();
getCompanyUser.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getCompany: function(){
var gr = new GlideRecord('sys_user');
gr.get(gs.getUserID());
if(gr.company.country == 'France')
return 'true';
else
return 'false';
},
type: 'getCompanyUser'
});
Referred from this thread.
Mark my answer correct & Helpful, if Applicable.
Thanks,
Sandeep