- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2019 07:09 AM
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();
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2019 10:38 AM
For some reason the addEncodedquery() did not work however splitting the queries and executing worked fine 🙂

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2019 07:15 AM
Hi there,
Since you are already using:
gr.addQuery('stateNOT IN6,7,8^u_is_planned=Unplanned^cmdb_ci.u_service_offering.u_offer_name=' + offername + '^ORDERBYsys_updated_on');
Why not use:
addEncodedQuery
Kind regards,
Mark
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2019 07:17 AM
This way you could also easily generate breadcrumb filters and copy the queries. Almost copy-pasting to get your addQuery running 🙂
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Mark
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2019 07:16 AM
gr = new GlideRecord('incident');
gr.addEncodedQuery('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();
}
try now

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-22-2019 07:18 AM
For AND conditions, just write another line with addQuery method.
For OR conditions, you can concatenate gr.addQuery(xx).addOrCondition(yy).
Otherwise you can use addEncodedQuery to write every condition in a single line, like:
gr.addEncodedQuery('u_configuration_itemIN' + current.u_configuration_item.toString());
Let me know if it helps.