addEncodedQuery with multiple ADD conditions

kafley_monami
Tera Contributor

Hi,

 

I have a situation here where I would like to add multiple ADD condition to addEncodedQuery.

Currently I have:

gr.addEncodedQuery("u_audit_planned_nextISNOTEMPTY^parent=b3f0fa471bxxxxx^u_type=Subsidiary");

But for variable 'u_type', I also need to add Production along with Subsidiary

I have tried

gr.addEncodedQuery("u_audit_planned_nextISNOTEMPTY^parent=b3f0fa471bxxxxx^u_type=Subsidiary^Production");

but didnt work out.

Any leads on this problem?

 

TIA

1 ACCEPTED SOLUTION

Iraj Shaikh
Mega Sage
Mega Sage

Hi,

 

To add multiple conditions with OR logic in ServiceNow using `addEncodedQuery`, you need to enclose the conditions in parentheses and use the OR operator (`^OR`). Here's how you can modify your query:

 

gr.addEncodedQuery("u_audit_planned_nextISNOTEMPTY^parent=b3f0fa471bxxxxx^u_type=Subsidiary^ORu_type=Production");

 

This query will retrieve records where `u_audit_planned_next` is not empty, `parent` is equal to "b3f0fa471bxxxxx," and `u_type` is either "Subsidiary" or "Production."

 

Remember to replace the field names and values with your actual field names and desired values. The key here is to group the conditions for `u_type` within parentheses and use the `^OR` operator between them.

 

Please mark it helpful.

View solution in original post

2 REPLIES 2

Iraj Shaikh
Mega Sage
Mega Sage

Hi,

 

To add multiple conditions with OR logic in ServiceNow using `addEncodedQuery`, you need to enclose the conditions in parentheses and use the OR operator (`^OR`). Here's how you can modify your query:

 

gr.addEncodedQuery("u_audit_planned_nextISNOTEMPTY^parent=b3f0fa471bxxxxx^u_type=Subsidiary^ORu_type=Production");

 

This query will retrieve records where `u_audit_planned_next` is not empty, `parent` is equal to "b3f0fa471bxxxxx," and `u_type` is either "Subsidiary" or "Production."

 

Remember to replace the field names and values with your actual field names and desired values. The key here is to group the conditions for `u_type` within parentheses and use the `^OR` operator between them.

 

Please mark it helpful.

Thanks @Iraj Shaikh.

This fixed my problem!