SC_REQ_ITEM-DDD and XYZ country users should not able to view AAA country records.

Udhayakumar_30
Tera Contributor

Conditions:

1.DDD and XYZ country users should not able to view AAA country records.(example sc_req_item table)

2.Particular group member (example group name: Banking) should not able to view the "sc_req_item records)

3.Both are based on the field "requested_for"

 

Bug: previously the first condition is working fine..when I try to add the 2nd condition. it breaks.I have pasted the BR below.

 

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


    var groupMemberGR = new GlideRecord('sys_user_grmember');
    groupMemberGR.addQuery('group', '21976e879f326210eeac95edygfkugli');
    groupMemberGR.addQuery('user', gs.getUserID());
    groupMemberGR.setLimit(1);
    groupMemberGR.query();
    if (groupMemberGR.next()) {
        current.addEncodedQuery('requested_for.country!=AAA^requested_for.country!=BBB');
    }
    var restrictedCountries = ['DDD','XYZ'];
    var userCountry = gs.getUser().getCountry();

    if (groupMemberGR.next() || restrictedCountries.indexOf(userCountry) > -1) {
        current.addEncodedQuery('requested_for.country!=AAA^requested_for.country!=BBB');
    }
	})(current, previous);

 

Please someone let me know ,what i need to modify/ what error i have made?

6 REPLIES 6

I have done in BR. but I have to implement in ACL

Nishant8
Giga Sage

Hello @Udhayakumar_30 , you can achieve the same using only one if condition. could you please try below and share the outcome?

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

    var groupMemberGR = new GlideRecord('sys_user_grmember');
    groupMemberGR.addQuery('group', '21976e879f326210eeac95edygfkugli');
    groupMemberGR.addQuery('user', gs.getUserID());
    groupMemberGR.setLimit(1);
    groupMemberGR.query();
    var restrictedCountries = ['DDD', 'XYZ'];
    var userCountry = gs.getUser().getCountry() + '';

    if ( groupMemberGR.next() || restrictedCountries.indexOf(userCountry) > -1 )
        current.addEncodedQuery('requested_for.country!=AAA^requested_for.country!=BBB');
})(current, previous);

 

Regards,

Nishant