Need script include for reference qualifier

Vamsi Krishna
Tera Contributor

Hi ,

We have a requirement to amend the existing reference qualifier which is called frpm script include.

We have Business unit approval variable on the catalog form which refers from sys_user table. and those business approvals should be the same from requestedp_for's business unit which is also referring from sys_user table.

 

For example:

there is a user called "test user"

and he has business unit as "Finance"

we have approvers in the business unit "finance" and if the requested_for has the business unit as finance , only thos approvers should be visible in the list.

 

Attaching the images for reference.

 

Here already we have the script for the above , but we are getting all the active and inactive users in the approval list.

We only need to get the users who are active only.

 

costCenterRefQualifier: function() {
        var finalQryStr = '';
 
        var bu = current.variables.u_requested_for.u_business_unit;
        if (!gs.nil(bu)) {
            finalQryStr = bu.u_business_unit_approvers + ',^sys_id!=' + gs.getUserID();
        }

        return 'sys_idIN' + finalQryStr;

    },
 
we need to get only the active business unit approvers.
 
Please help in modifying the above method.
 
4 REPLIES 4

Ivan Betev
Mega Sage
Mega Sage

Hello there,

 

If I correctly understand this, then you need an active records check before returning.

 

Would that work?

 

costCenterRefQualifier: function() {
    var finalQryStr = '';

    var bu = current.variables.u_requested_for.u_business_unit;
    if (!gs.nil(bu)) {
        var approverRecords = new GlideRecord('sys_user');
        approverRecords.addActiveQuery();
		approverRecords.addQuery('sys_id','IN',bu.u_business_unit_approvers);
        approverRecords.query();

        var approvers = [];

        while (approverRecords.next()) { approvers.push(approvers.getUniqueValue()); }

        finalQryStr = approvers.join(',') + '^sys_id!=' + gs.getUserID();
    }

    return 'sys_idIN' + finalQryStr;
},

 

 

Regards, Ivan

Hi @Ivan Betev  ,

yes , you are right , it should return only the active users as approvers.

I tried using the above script but its not working.

The script not returning any values , the field showing as empty.

 

please find the attached snap.

 

Hi @ Vamsi Krishna  ,

 

I've updated the script because I found a tiny typo there. Could you try again?

 

Could you please paste a screenshot of a ref qualifier field?

 

Regards, Ivan

Hi @Ivan Betev ,

 

Please find the below screenshot for reference qualifier field

VamsiKrishna_0-1704793414085.png