Update Catalog UI Policy

dvelloriy
Kilo Sage

Hello,

I have a catalog UI policy applied to a catalog item. It is making a variable on the catalog form read-only on load.

Requirement is to make this variable editable for users whose falls under certain departments. (user.department.id == 400123,400234,400345 and so on)

How can I include this condition in the UI policy?

 

 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@dvelloriy 

not possible using UI policy

Please use onLoad catalog client script + GlideAjax and check if logged in user department ID IS ONE OF those values

Script Include: It should be client callable

var checkRecords = Class.create();
checkRecords.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    checkRecordPresent: function() {
        var id = this.getParameter('sysparm_userID');
        var allowedDepartments = ['400123', '400234', '400345']; // Add your department IDs here

        var gr = new GlideRecord('sys_user');
        gr.addQuery('sys_id', id); // Use valid field name here
        gr.query();
        if (gr.next()) {
            if (allowedDepartments.indexOf(gr.department.id.toString()) != -1) {
                return 'found';
            } else {
                return 'not found';
            }
        }
        return 'not found';
    },

    type: 'checkRecords'
});

AnkurBawiskar_0-1741183818882.png

 

onLoad client script:

function onLoad() {

    var ga = new GlideAjax('checkRecords');
    ga.addParam('sysparm_name', "checkRecordPresent");
    ga.addParam('sysparm_userID', g_user.userID);
    ga.getXMLAnswer(function(answer) {
        if (answer == 'found')
            g_form.setReadonly('variableName', false);
        else
            g_form.setReadonly('variableName', true);
    });
}

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

7 REPLIES 7

Hi Ankur,

Its not working and giving this error

AbstractAjaxProcessor undefined, maybe missing global qualifier

@dvelloriy 

ensure you create script include and client script in same scope.

Seems you are working in scoped app and trying to create script include + client script in global scope

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, 

I created both script include and client script in scoped app only. 

Issue got fixed when i updated the below line of code and included global.AbstractAjaxProcessor instead.

checkRecords.prototype = Object.extendsObject(AbstractAjaxProcessor, {