How to add "AND" condition in addquery()

Manikandan2
Kilo Expert

Hi,

The below script is not working properly. In my script i want to add query with "AND" condition to check multiple fields like 

  • When state is 6,7,8
  • u_is_planned = Unplanned
  • Service Offering = Offername

If all the conditions are satisfied only then i want to update the description field. I know there is a syntax error in the below query. What correction i would need to do ?

gr = new GlideRecord('incident');
gr.addQuery('stateNOT IN6,7,8^u_is_planned=Unplanned^cmdb_ci.u_service_offering.u_offer_name=' + offername + '^ORDERBYsys_updated_on');
gr.query();
while (gr.next()) {
gr.description = gr.description + '.';
gr.update();
}

1 ACCEPTED SOLUTION

Manikandan2
Kilo Expert

For some reason the addEncodedquery() did not work however splitting the queries and executing worked fine 🙂 

View solution in original post

7 REPLIES 7

Nithish1
Tera Guru

Hello Manikandan,

Instead of addQuery you can do 'addEnCodedQuery' and copy the query from the list filter.

Regards,

Nithish

siva_
Giga Guru

Hello Manikandan, 

 

For writing AND queries , if you are using multiple sequential addQuery statements it will treat that as an AND condition. 

if for writing OR queries in Glide Record, we have use something like addOrCondition 

 

Whenever you are writing complex queries, it is recommended to go to the list layout of that particular table and then build the filter condition you want to apply and MAKE SURE to right click at the end of the filter and click "copy query" . Once done , your query will be copied into the clipboard and by using the addEncodedQuery() of the GlideRecord class you can paste the query condition copied into the function as parameter. That really helps 

 

Mark this response as correct/helpful if that really helps

 

 

Thanks,

Siva

Manikandan2
Kilo Expert

For some reason the addEncodedquery() did not work however splitting the queries and executing worked fine 🙂