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

Anurag Tripathi
Mega Patron
Mega Patron

This is the right syntax

 

loc.addQuery('name',store_num);

 

although you are setting the value of store_num as gr.x, i dont know what that is.

-Anurag

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.

Thanks Mark that helps.

I am getting a number from var store_num. So I have converted that by adding .toString(). Now its working fine.

Mark, Encountered one issue while testing this.

It seems like this script updated just about all projects to state 17 . This is not correct. It needs to look for a match of the number. It is looking for contains right now, which is then updating all of them. For example, I entered 1005, then ran the script. That project found 100 - Earlham as the match and changed the state. It should've only done this if the location number is exactly 1005.

 

Can you help me out with this ?