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

Ankur Bawiskar
Tera Patron
Tera Patron

@PawanKumarR 

so what debugging did you do?

if that property holds comma separated sysIds of catalog item (sc_cat_item) then this should work fine

var encodedQuery = 'cat_item.sys_idIN' + gs.getProperty('a_b_c');

ritmGr.addEncodedQuery(encodedQuery);

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader