Hide Work order for specific condition(field on core_company table, and country code)

Rahul k
Tera Guru

There is Field on core_company table. Field name: model(choice= AA, BB, CC, DD)

There is Field sys_user table: Field name: country code.

 

Condition: If the user from non-America and core_company.model field value is AA then those work order should not visible for that user.

Note: Company field is also visible on Work order form.

How to achieve this?? any other approach than ACL??

1 ACCEPTED SOLUTION

Rahul k
Tera Guru

Removed condition from when to run.

Rahulk_0-1722945122473.png

 



Written below script and its working:

(function executeRule(current, previous /*null when async*/ ) {

    var wmGroup = 'sys_id';   // sys_id of group
    var gr = new GlideRecord('sys_user');
    gr.get(gs.getUserID());
    var countryCode = gr.getValue('country');
   
    var user = gs.getUser();

    if (countryCode != 'DE') {

        var grM = new GlideRecord('sys_user_grmember');
        grM.addQuery('user', gs.getUserID());
       grM.addQuery('group', wmGroup);
        grM.query();

        if (grM.next()) {
            current.addEncodedQuery('company.u_operationNOT INd4,d7');
        }
    }

})(current, previous);

View solution in original post

4 REPLIES 4

Bhavya11
Kilo Patron

hi @Rahul k ,

 

you are hiding from list view right? then go with Before query business rule.

 

Thanks,

BK

Rahul k
Tera Guru

Hi Bhavya,
I written before Query BR as below but still its not loading:

(function executeRule(current, previous /*null when async*/ ) {
    var gr = new GlideRecord('sys_user');
    gr.get(gs.getUserID());
    var countryCode = gr.getValue('country');
   // gs.info('The country code for the user\'s location is: ' + countryCode);
    if (countryCode != 'DE') {
        current.setAbortAction(true);
    } else {
        current.setAbortAction(false);
    }
})(current, previous);

Rahul k
Tera Guru

Rahulk_0-1722690348404.png

I want to hide record for above condition. 
Company field is on Work order table and operation field is on core company table. If the operation field value is E4 ir E7 then those record should not visible for non Germany users

Rahul k
Tera Guru

Removed condition from when to run.

Rahulk_0-1722945122473.png

 



Written below script and its working:

(function executeRule(current, previous /*null when async*/ ) {

    var wmGroup = 'sys_id';   // sys_id of group
    var gr = new GlideRecord('sys_user');
    gr.get(gs.getUserID());
    var countryCode = gr.getValue('country');
   
    var user = gs.getUser();

    if (countryCode != 'DE') {

        var grM = new GlideRecord('sys_user_grmember');
        grM.addQuery('user', gs.getUserID());
       grM.addQuery('group', wmGroup);
        grM.query();

        if (grM.next()) {
            current.addEncodedQuery('company.u_operationNOT INd4,d7');
        }
    }

})(current, previous);