Catalog Client Script (Show the subcategory field only if you have an ITIL role)

PaulineCovely
Tera Contributor
When we installed our system, our consultants created the following catalog client script.  It allows individuals with the job_family (custom field) equal to IT to select the subcategory of data center; otherwise, you cannot see that subcategory as a selection.  
 
I need to change this to do the same thing, but it would be if you have an ITIL Role.  Can someone assist me with this?  I have not done this before, but if my research is correct, I would need to use the sys_user_has_roles table and the role field.
 
Thank you in advance.
-----------------------------------------------------------------------
 
function onChange(control, oldValue, newValue, isLoading) {
    if (newValue == '') {
        return;
    }
 
    var ga = new GlideAjax('ServicePortalUtils');
    ga.addParam('sysparm_name', 'getUserDetails');
    ga.addParam('sysparm_user', newValue);
    ga.getXML(updateSubcategory);
}
 
function updateSubcategory(response) {
    var answer = response.responseXML.documentElement.getAttribute("answer");
    if (answer) {
        var user = JSON.parse(answer);
if (user.job_family == "IT")
            g_form.addOption("subcategory", "data_center", "Data Center", 3);
        else
            g_form.removeOption("subcategory", "data_center");
        if (user.job_family == "IT" || user.business_unit == 67200) {
            g_form.removeOption("subcategory", "azure");
            g_form.addOption("subcategory", "azure", "Azure Resources", 1);
        } else
            g_form.removeOption("subcategory", "azure");
    }
}
2 REPLIES 2

Brad Bowman
Kilo Patron
Kilo Patron

Hi Pauline,

In the Catalog Client Script, you can use something like this without a Glide Ajax call in this case:

if (g_user.hasRole('itil')) {
    g_form.addOption....
}

 

Sumanth16
Kilo Patron

Hi @PaulineCovely ,

 

Create Catalog Client script is an onChange of Category field. 

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var cat = g_form.getValue('category');
var subcat = g_form.getValue('sub_category');
if (cat == "IT Security" && (!g_user.hasRole('itil'))) {
alert("entered");
g_form.removeOption('sub_category', 'Security Exception');
//g_form.removeOption('sub_category','Security Exception','Security Exception');
}
}

 

If I could help you with your Query then, please hit the Thumb Icon and mark it as Correct !!

 

Thanks & Regards,

Sumanth Meda