How to apply multiple OR conditions to addQuery - on Relationship (sys_relationship) script

Andrew Newman
Tera Contributor

Hello,

On the change request form, I need to add a second related list which refers to conflicts, in this case purely scheduling conflicts (i.e. date and time, as opposed to CI conflicts) and the table we are querying is a custom table which contains a blend of Change and Release records.

I created a sys_relationship and added the section to the Change request form, and called it 'Scheduling Conflicts'. It is displaying some records as expected. However, the query I have is not applying all of the conditions. 

I could really use some help to guide me where I have gone wrong. I suspect I have misused the addCondition / addOrConditions.

The sys_relationship record:
Name: Scheduling Conflicts

Applies to table: change_request
Queries from table: u_my_table (this contains the blended list of change and release records).
Here is the script containing the conditions.


(function refineQuery(current, parent) {
current.addQuery('u_state', '!=', 'Closed Complete');
current.addQuery('u_state', '!=', 'Cancelled');
current.addQuery('u_number.number', '!=', parent.number)


current.addQuery('u_planned_start_date', '<=', parent.start_date).addCondition('u_planned_end_date', '>=', parent.start_date);
current.addOrCondition('u_planned_start_date', '>=', parent.start_date).addCondition('u_planned_end_date', '<=', parent.end_date);
current.addOrCondition('u_planned_start_date', '>=', parent.start_date).addCondition('u_planned_start_date', '<=', parent.end_date).addCondition('u_planned_end_date', '>=', parent.end_date);
current.addOrCondition('u_planned_end_date', '<=', parent.start_date).addCondition('u_planned_end_date', '>=', parent.end_date);
;

})(current, parent);

6 REPLIES 6

Allen Andreas
Administrator
Administrator

Hi,

If you don't mind, please use the appropriate forum feature: "Insert/Edit code sample" when pasting code so that it remains organized and easier to read:

For information related to GldieRecord and addQuery, addOrCondition, etc. please refer to documentation such as: https://developer.servicenow.com/dev.do#!/reference/api/sandiego/server/c_GlideQueryConditionScopedA...

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Andrew Newman
Tera Contributor

Hi Allen,

 

thank you for the swift reply and apologies if I missed the facility to properly insert code samples. I will use this in future.

 

I have seen that article you linked me to but I don't think it covers my specific query - or at least I don't see how it does because my conditions are within a refineQuery function - so I do not issue the .query() statement.

 

Thanks

Andy

 

Hi,

The above was giving you guidance on formatting and examples of using addOrCondition, etc.

Not meaning every line may be applicable to you.

My apologies if you felt it was irrelevant, but in your original post you said:

"I could really use some help to guide me where I have gone wrong. I suspect I have misused the addCondition / addOrConditions."

 


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Hitoshi Ozawa
Giga Sage
Giga Sage

Hi Andrew,

If the script in the question is not working as intended, would appreciate if a sql statement can be written on what the query is intended to do.