The CreatorCon Call for Content is officially open! Get started here.

addQuery() not working ?

SaiRaviKiran Ak
Giga Guru

Hi team,

 

I have a field called X(String) in project table. Now i need to compare the value of X with name field in location table.

If name field in the location table contains X value(Ex: If X =1001 and my location values are like :1001 - abc -1) then I need to change the state of a project.

I am trying to query the location table to see whether the name field contains value. Unfortunately my addQuery() is not working as it was returning all the locations from the location table.

Below is my code :

 

var store_num;
var gr;
gr = new GlideRecord("pm_project");
gr.addQuery("top_portfolio","4374167e4f2756007790a3938110c75a");
gr.addQuery("X","!="," ");
gr.query();
gs.info("proj count"+gr.getRowCount());
while (gr.next()) {
store_num =gr.X;
gs.info("store numbr "+store_num);

var loc = new GlideRecord("cmn_location");
loc.addQuery('nameLIKE',store_num); // This is not working (Also tried with loc.addQuery('name','CONTAINS',store_num);
loc.query();
gs.info("countloc"+loc.getRowCount());
if (loc.next()) {
gr.u_project_state = 17;
gr.update();
}
}

Any help would be appreciated.

Thanks,

Ravi

 

 

 

1 ACCEPTED SOLUTION

Mark Stanger
Giga Sage

loc.addQuery('name', 'CONTAINS', store_num); is the correct syntax.

What do you get in your logs when you log out 'store_num'?  Also, if 'store_num' is somehow stored as a  numeric field (it shouldn't be) you'll have to do 'store_num.toString()' for the comparison to work.

View solution in original post

6 REPLIES 6

loc.addQuery('name', store_num); should look for an exact match.

Shweta KHAJAPUR
Tera Guru

Hi,

Try query as below,

loc.addEncodedQuery("nameLIKE"+store_num);