How to pass javascript function into query Business rule?

swathigangadhar
Tera Expert

Hi,

Thanks in adv,

I have an issue regarding Query business rule, while i am trying to do query business rule to query the records its not retrieving.

here i am using below script include to retrieve the array of sysids.

fd.png

I am calling this script iclude in a query business rule as shown below to query the records.

current.addEncodedQuery("sys_id=javascript:AssetAccess()");

tedsdtd.png

but its not working,Please help me out where i am missing.

8 REPLIES 8

larstange
Mega Sage

Hi



You need to run the function within the business rule instead



current.addEncodedQuery('sys_id=' + AssetAccess());


Thank you for the response Lars,



I tried the same but no luck


current.addEncodedQuery('sys_id=' + AssetAccess());



if possible can u provide the code which is working.



Thank you,



Chuck Tomasi
Tera Patron

Hi Swathi,



I noticed a few things that need changing... first, when you are in the while loop, use gr.getValue('sys_id'),



var arr = [];



// do you query



while (gr.next()) {


        arr.push(gr.getValue('sys_id'));


}



// return the comma separated values


return arr.join(',');




Then in your query BR,



var queryStr = 'sys_idIN' + AssetAccess();



current.addEncodedQuery(queryStr);


HI Thomasi,



Thank you for the response.



If we use the below code it will work fine for limited sysids.


var queryStr = 'sys_idIN' + AssetAccess();


current.addEncodedQuery(queryStr);



For example if we are querying 1000 sysids and retrieving 1000 records then we are getting error (URL limitation exceeds) because this encodedquery stitch the sysids and pass it to the URL.



Due to this we are trying to pass all sysids as a java script function to overcome URL Limitation error.So can u help me out how to pass the javascript function in a Encodedquery.