The CreatorCon Call for Content is officially open! Get started here.

User Criteria script for service catalog not returning true

ConradJ
Tera Contributor

I have the below script configured on User Criteria to set Available For on a Catalog Item but it is not working even though the User Sysid is in the list of Approvers.

 

The output is returned as false when the below is shown in the debug logs. I am guessing there is an issue with the data but it is very difficult to troubleshoot since the User Criteria is cached.

 

Does anyone have any tips or guidance on where I went wrong?

 

Approvers found: 27e3664edb8928502948789e3b961992,0cf326c61b856850b85e2f06bd4bcbda,abe3e2c61b856850b85e2f06bd4bcb65,f3f36e4edb8928502948789e3b9619c8

Starting checkCondition function with user_id: f3f36e4edb8928502948789e3b9619c8

gsSysid not found in techApprovers: f3f36e4edb8928502948789e3b9619c8

 

 

 

checkCondition();

function checkCondition() {
    var gsUser = new GlideRecord('sys_user');
    var gsSysid = user_id;
    gs.info('Starting checkCondition function with user_id: ' + user_id);
    
    if (gsUser.get(user_id)) {
        gs.info('User record found for user_id: ' + user_id);

        var company = gsUser.company ? gsUser.company.name : null;
        gs.info('Company name: ' + company);
        var gsName = gsUser.name;
        gs.info('User name: ' + gsName);

        if (!company) {
            gs.info('Company is null for user_id: ' + user_id);
            return false;
        }

        var accountGr = new GlideRecord("customer_account");
        accountGr.addEncodedQuery("name=" + company);
        gs.info('Encoded query added for company: ' + company);

        accountGr.query();
        gs.info('Query executed on customer_account table');

        var techApprovers = [];
        while (accountGr.next()) {
            techApprovers.push(accountGr.u_technical_approver.toString().trim()); // Ensure each approver is a trimmed string
        }
        gs.info('Approvers found: ' + techApprovers);

        if (techApprovers.indexOf(gsSysid) > -1) {
            gs.info('gsSysid found in techApprovers: ' + gsSysid);
            return true;
        } else {
            gs.info('gsSysid not found in techApprovers: ' + gsSysid);
            return false;
        }
    } else {
        gs.info('User record not found for user_id: ' + user_id);
        return false;
    }
}

 

 

Thanks,

Conrad

0 REPLIES 0