Query business rule is not working as expected

tsoct
Tera Guru

Hello all,

We have a before query business rule to filter ritm to be displayed. However, it doesnt seems work. What could i missed?

 

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

    var groups = j2js(gs.getUser().getMyGroups().toArray());
    var groupsArray = groups.toString().split(','); 
    var groupsParentArray = groups.parent.toString().split(','); //Parent of my groups
    var arr = [];

    var gr = new GlideRecord('sys_user_group');
    gr.addQuery('parent''IN', groupsArray).addOrCondition('parent''IN', groupsParentArray); 
    gr.query();
    while (gr.next()) {
        arr.push(gr.getValue('sys_id'));
    }
    
    var arrayUtil = new global.ArrayUtil();
    var finalArray = arrayUtil.concat(groupsArray, groupsParentArray, arr);
    finalArray = arrayUtil.unique(finalArray);
    var u = gs.getUserID(); //Get the sys_id value of the current user
    
    var qc = new GlideRecord('sc_req_item');
    qc.addOrCondition("opened_by", u);
    qc.addOrCondition("requested_for", u);
    qc.addOrCondition("watch_list""CONTAINS", u);
    qc.addOrCondition("assignment_group.sys_idIN" + finalArray);
    current.addEncodedQuery(qc);
    
})(current, previous);

 

1 ACCEPTED SOLUTION

Sai Shravan
Mega Sage

Hi @tsoct ,

It seems that there might be an issue with the way the encoded query is constructed

(function executeRule(current, previous /*null when async*/) {
  var groups = j2js(gs.getUser().getMyGroups().toArray());
  var groupsArray = groups.toString().split(',');
  var groupsParentArray = groups.parent.toString().split(','); // Parent of my groups
  var arr = [];

  var gr = new GlideRecord('sys_user_group');
  gr.addQuery('parent', 'IN', groupsArray).addOrCondition('parent', 'IN', groupsParentArray);
  gr.query();
  while (gr.next()) {
    arr.push(gr.getValue('sys_id'));
  }

  var arrayUtil = new global.ArrayUtil();
  var finalArray = arrayUtil.concat(groupsArray, groupsParentArray, arr);
  finalArray = arrayUtil.unique(finalArray);
  var u = gs.getUserID(); // Get the sys_id value of the current user

  var qc = "opened_by=" + u +
    "^ORrequested_for=" + u +
    "^ORwatch_listLIKE" + u +
    "^ORassignment_groupIN" + finalArray.join(',');

  current.addEncodedQuery(qc);
})(current, previous);

 

Regards,

Shravan

Please mark this as helpful and correct answer, if this helps you

Regards,
Shravan
Please mark this as helpful and correct answer, if this helps you

View solution in original post

1 REPLY 1

Sai Shravan
Mega Sage

Hi @tsoct ,

It seems that there might be an issue with the way the encoded query is constructed

(function executeRule(current, previous /*null when async*/) {
  var groups = j2js(gs.getUser().getMyGroups().toArray());
  var groupsArray = groups.toString().split(',');
  var groupsParentArray = groups.parent.toString().split(','); // Parent of my groups
  var arr = [];

  var gr = new GlideRecord('sys_user_group');
  gr.addQuery('parent', 'IN', groupsArray).addOrCondition('parent', 'IN', groupsParentArray);
  gr.query();
  while (gr.next()) {
    arr.push(gr.getValue('sys_id'));
  }

  var arrayUtil = new global.ArrayUtil();
  var finalArray = arrayUtil.concat(groupsArray, groupsParentArray, arr);
  finalArray = arrayUtil.unique(finalArray);
  var u = gs.getUserID(); // Get the sys_id value of the current user

  var qc = "opened_by=" + u +
    "^ORrequested_for=" + u +
    "^ORwatch_listLIKE" + u +
    "^ORassignment_groupIN" + finalArray.join(',');

  current.addEncodedQuery(qc);
})(current, previous);

 

Regards,

Shravan

Please mark this as helpful and correct answer, if this helps you

Regards,
Shravan
Please mark this as helpful and correct answer, if this helps you