How to parse sysparm_query ?

peter_repan
Tera Guru

Hi all,

let's imagine that I have following query: u_group_item=true^u_parentISEMPTY^u_descriptionLIKEcomp.

Is there a way in ServiceNow how can I get following object or array of key/pair values from filter conditions?

{

u_group_item: true,

u_parent:'',

u_description:comp

}

I do not need operators, only columns and values.

Thank you

3 REPLIES 3

Harish Murikina
Tera Guru

Hi Peter,



                Try something like below.



var desc = '';


var qry = 'u_group_item=true^u_parentISEMPTY^u_descriptionLIKEcomp.';




var spli_qry = qry.split('^');




var len = spli_qry.length;




for(var i=0; len>i;i++)


{




var spli_rec = spli_qry[i].split('=');


desc += spli_rec[0]+'   :'+spli_rec[1]+'\n';


}




alert(desc);


Hi Harish,



thanks a lot, I was thinking about parsing like this. It is a little bit more complicated because there is not always only '^' but sometimes also '^EQ' or '^OR'. I admit that this was not a good example .


Also splitting around '=' is not efficient when I have condition like u_parentISEMPTY.



There can occur many cases which should be handled in different ways, I wonder if there is any OOB function which can handle this.


Not sure is there any OOB script available for this but we can do it script .