Business rule - Encoded Query

PawanKumarR
Tera Contributor

Hi All,

 

I have created a system properties "a_b_c" where i have stored three sys ids of a catalog in form of a,b,c.

now this i have to use in business rule. when my catalog is any of this (a or b or c). then do xyz.

i have to put this sys property a_b_c in Encoded Query of a BR.
i have used but its not selecting that three catalog ids.

script:

var sysIds = gs.getProperty('a_b_c').split(',');

var encodedQuery = ' ';
            for (var i = 0; i < sysIds.length; i++) {
                if (i > 0) {
                    encodedQuery += '^OR';
                }
                encodedQuery += 'cat_item=' + sysIds[i];
            }

var ritmGr = new GlideRecord('sc_req_item');
            ritmGr.addQuery("opened_by", current.u_owner_id);
            ritmGr.addEncodedQuery(encodedQuery);
            ritmGr.addActiveQuery();
            ritmGr.query();
            if (ritmGr.next()) {

1 ACCEPTED SOLUTION

J Siva
Tera Sage

Hi @PawanKumarR 

Try below script..

var sysIds = gs.getProperty('a_b_c').toString();

var encodedQuery = 'cat_itemIN' + sysIds;
var ritmGr = new GlideRecord('sc_req_item');
ritmGr.addQuery("opened_by", current.getValue('u_owner_id')); 
ritmGr.addEncodedQuery(encodedQuery);
ritmGr.addActiveQuery();
ritmGr.query();
while (ritmGr.next()) {
    //YOUR LOGIC HERE
}

Hope this helps .

Regards,

Siva

View solution in original post

15 REPLIES 15

J Siva
Tera Sage

Hi @PawanKumarR 

Try below script..

var sysIds = gs.getProperty('a_b_c').toString();

var encodedQuery = 'cat_itemIN' + sysIds;
var ritmGr = new GlideRecord('sc_req_item');
ritmGr.addQuery("opened_by", current.getValue('u_owner_id')); 
ritmGr.addEncodedQuery(encodedQuery);
ritmGr.addActiveQuery();
ritmGr.query();
while (ritmGr.next()) {
    //YOUR LOGIC HERE
}

Hope this helps .

Regards,

Siva

Partially working for only one sys id, not working for other two

This should work. I just tested this in my PDI.

1. Check if the sys_ids stored in the system property are valid.

2. Check if the BR is getting triggered or not using script tracer.

Its working for only one sys id