Before Query business rule not working

Lakshmi53
Tera Contributor

below script i written in before query business rule. but it's not working as expected. whole table data not able to view.

 

in details system property i have 2 records sys_id. i need to view those only once i open table but table shoing with empty record

 

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

    current.addQuery("u_type", "!=", "info").addOrCondition('u_type', gs.getProperty('details'));
   
})(current, previous);
5 REPLIES 5

Nilesh Pol
Tera Guru

Hi @Lakshmi53 You can try below updated script:

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

var detailsSysId = gs.getProperty('details');
if (detailsSysId) {
current.addQuery('u_type', '!=', 'info'); // Exclude "info" records
current.addOrCondition('u_type', detailsSysId); // Add OR condition for system property sys_id
}

})(current, previous);

 

sunil maddheshi
Tera Guru

@Lakshmi53 

 

  • If details contains multiple sys_ids, it's probably stored as a comma-separated string (e.g., "sys_id1,sys_id2").
  • .addOrCondition() works on individual conditions, and if gs.getProperty('details') returns a string, it won't properly filter for multiple values.  Can you try with below updated code

 

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

    var detailsSysIds = gs.getProperty('details'); // Get system property value

    if (detailsSysIds) {
        var sysIdArray = detailsSysIds.split(','); // Convert to array

        var gr = current.addQuery("u_type", "!=", "info");
        gr.addOrCondition("sys_id", "IN", sysIdArray);
    }

})(current, previous);

 

 

Please mark correct/helpful if this helps you!

 

Shivalika
Mega Sage

Hello @Lakshmi53 

 

How have you equated "u_type" field with both "info" and "gs.getproprty - which returns sys_id". 

 

I mean the field type can either be string or be reference, how both ? Can you run this filter in the list view , copy query from the filter itself and add it in the business rule like "addEncodedQuery" and check once. 

 

After that whatever field values you have stored in property table just replace that in the query you copied. It will give you accurate result. 

 

Kindly mark my answer as helpful and accept solution if it helped you in anyway,

 

Regards,

Shivalika 

 

My LinkedIn - https://www.linkedin.com/in/shivalika-gupta-540346194

 

My youtube - https://youtube.com/playlist?list=PLsHuNzTdkE5Cn4PyS7HdV0Vg8JsfdgQlA&si=0WynLcOwNeEISQCY

Brad Bowman
Kilo Patron
Kilo Patron

Your OR condition reads "the value of the u_type field equals the contents of the system property".  If the system property contains two values, comma-separated, and you are looking for u_type records that are one or the other of those values, then you need to use the IN operator:

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

    current.addQuery("u_type", "!=", "info").addOrCondition('u_type', 'IN', gs.getProperty('details'));
   
})(current, previous);