How to avoid two gliderecord queries for same table.

saibharath
Tera Contributor

How to avoid duplicate gliderecord queries in this case

  • obj is an object on hardware table
  •  assuming country is 'spain' and model is 'laptop' and this value is stored in obj object which I received from bulk import.

 

 

var gr = new GlideRecord("asset_tag_rule");
gr.addEncodedQuery("country=" + obj.country + "^model=" + obj.mdl); // we are checking in asset_tag_rule table if spain country and laptop model is there.
gr.query(); // querying and assume I get one record

if (gr.next()) {
var grINCR = new GlideRecord("asset_tag_rule");// how to avoid this step
grINCR.addEncodedQuery("country=" + gr.country + "^u_ctgry_prfx=" + gr.u_ctgry_prfx);// here I am checking asset_tag_rule table if spain country and ctgry_prfx value is present in this table which we get from first glide object(gr)
grINCR.query();
while (grINCR.next()) {
grINCR.net = 3;
grINCR.update();
}
}

 

 

 

  • I can have multiple values of u_ctgry_prfx (which I get from gr) and country combination from asset_tag_rule table hence used  while in the end to update.

@Ankur Bawiskar  or anyone pls suggest a way

6 REPLIES 6

Samaksh Wani
Giga Sage
Giga Sage

Hello @saibharath 

 

In the first step only as you are using Encoded Query use AND Operator between country and category for getting category values of only spain country.

 

Plz mark my solution as Accept, If you find it helpful.

 

Regards,

Samaksh

Hi @Samaksh Wani

 

This won't work please go through the code properly, I won't have category in the beginning 

Hello @saibharath 

 

Modify your addEncodedQuery Code with mine.

 

gr.addEncodedQuery("country=" + obj.country + "^u_ctgry_prfxISNOTEMPTY^model=" + obj.mdl);

 

Plz mark my solution as Accept, If you find it helpful.

 

Regards,

Samaksh

 

Hi @Samaksh WaniT

his is wrong because in this case I'll be getting records with model as laptop but if you check code properly I am only taking only ctgry_prefix to use in second query, so ctgry_prefix can have different models also not only laptop