Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Best way to do Or queries ? #17

Open
ajmyers01 opened this issue Apr 5, 2017 · 4 comments
Open

Best way to do Or queries ? #17

ajmyers01 opened this issue Apr 5, 2017 · 4 comments

Comments

@ajmyers01
Copy link

I want to pull back all tImeEntry records that have a type of 1 or 2. how would i go about constructing that using an add_condition block ?

query = AutotaskAPI::QueryXML.new do |query|
query.entity = 'timeentry'
end

year_ago = (DateTime.now - 1.year).to_formatted_s(:iso8601)                                                                                             
query.add_condition('ticketid', 'equals', ticket_id)                                                                                                        

query.add_condition('type', 'equals', 2)  || query.add_condition('type', 'equals', 1) 
@scoop
Copy link
Owner

scoop commented Apr 5, 2017

I'm afraid this will need an extension of the AutotaskAPI::QueryXML class. An example from the Autotask API docs:

<query>
  <condition>
    <field>firstname
      <expression op="equals">Joe</expression>
    </field>
  </condition>
  <condition operator="OR">
    <field>lastname
      <expression op="equals">Brown</expression>
    </field>
  </condition>
</query>

Basically what's missing is the addition of the operator attribute to the generated XML. I don't have any immediate plans to add this as my time right now is fairly limited.

@ajmyers01
Copy link
Author

Okay I'll clean the data after I retrieve it all.

I'll try to find some time to look into the queryxml method more in depth and see if i can propose a solution.

Thanks @scoop

@kbni
Copy link

kbni commented Jul 21, 2017

I'm not a ruby developer, but I previously hacked something together for more complex queries (perhaps some of it might be of use?):
https://github.com/kbni/autotask_api/blob/master/lib/autotask_api/query_builder.rb

@trepidity
Copy link
Contributor

Interesting how you added the method_missing. That's something that has been biting me hard on the current API.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants