Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

GlideRecord addQuery comparing two field values

toneyvecchio1
Tera Expert

Greetings,

I was hoping for assistance, likely a simple answer but too much time has been spent already trying 70 different methods and I am sure someone here will know it.

Stripped down to its basic form I am trying to addQuery against 1 field on a table and 1 field on another table, stepping through a reference field.

var getCvr = new GlideRecord('pm_portfolio_project');

getCvr.addQuery('project.u_start_date','=','u_project_start_date');

getCvr.query();

while(getCvr.next()) {
//do stuff

getCvr.update();
}

I have confirmed the project.u_start_date works fine, I am assuming its comparing 'u_project_start_date' as a literal string and not evaluating the field from the original table. Any advise?

1 ACCEPTED SOLUTION

Replace the addquery with this


getCvr.addEncodedQuery('pm_project.start_dateSAMEASstart_date@day')



If this doesn't work, open the table > filter the record as needed > right click on the query end >do a copy query> use it in encoded query


View solution in original post

5 REPLIES 5

Kalaiarasan Pus
Giga Sage

Exactly. It will treat anything within quotes as a string lliteral.


So try




getCvr.addQuery('project.u_start_date',u_project_start_date);


Gave it a run, pretty reasonable but to no avail.



Here is the code, just stamping a string field to test functionality.


var getCvr = new GlideRecord('pm_portfolio_project');


getCvr.addQuery('project.u_start_date',u_project_start_date);
getCvr.query();


while(getCvr.next()) {
          getCvr.u_gtg_plan = 'Found a match';
          getCvr.update();
}




Both date fields are basic, no time.


Case 1 = Expected Positive


Case 2 = Expected Negative


Case 3 = Earlier Test with simple addQuery



find_real_file.png


Replace the addquery with this


getCvr.addEncodedQuery('pm_project.start_dateSAMEASstart_date@day')



If this doesn't work, open the table > filter the record as needed > right click on the query end >do a copy query> use it in encoded query


And it found a match! Variable string was different but you're right once I grabbed the query from the filter and used encoded it worked. Thank you so much.