
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-12-2018 04:52 AM
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 X 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
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-12-2018 04:57 AM
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-14-2018 04:38 AM
loc.addQuery('name', store_num); should look for an exact match.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-12-2018 05:03 AM
Hi,
Try query as below,
loc.addEncodedQuery("nameLIKE"+store_num);