scoop / autotask_api

Ruby API wrapper for the Autotask WebService API
MIT License
14 stars 9 forks source link

What is the best way to query condition all objects from 1 year ago. #14

Closed ajmyers01 closed 8 years ago

ajmyers01 commented 8 years ago

I'm trying to get all time entries for a ticket within the last year.

Is there a specific Condition for comparing dates ?

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('dateworked', 'GreaterThan', year_ago)                                                                                                    
@client.query = query
scoop commented 8 years ago

I've successfully used something like:

@query.add_condition 'CreateDate', 'GreaterThan', 3.months.ago.to_s

It might be a matter of simply calling .to_s on your date.