How to avoid two gliderecord queries for same table.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2023 07:35 AM - edited 10-06-2023 08:31 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2023 07:43 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2023 07:53 AM
This won't work please go through the code properly, I won't have category in the beginning
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2023 11:35 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-07-2023 01:27 AM
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