How to search for 'Yesterday'?

I want to find all part Items with a created_on date of Today - easy. Now I want to Save this search to the TOC so users can run it daily - not so easy.

I am trying to search for "Yesterday" in a date field, using AML.
this:
<Item type="Part" action="get" page="1" pagesize="200" maxRecords="" returnMode="itemsOnly">
 <created_on condition="gt">yesterday</created_on>
 <created_on condition="lt">tomorrow</created_on>
 <generation condition="ge">1</generation>
</Item>

In my OnBeforeGet, I find the value "Yesterday" and substitute it for yesterday's date.
this:
<Item type="Part" action="get" page="1" pagesize="200" maxRecords="" returnMode="itemsOnly">
 <created_on condition="gt">2019-05-02T00:00:00</created_on>
 <created_on condition="lt">2019-05-02T23:59:59</created_on>
 <generation condition="ge">1</generation>
</Item>

If I return this, then I get the error:
<SOAP-ENV:Envelope>
-<SOAP-ENV:Body>
-<SOAP-ENV:Fault>
 <faultcode>SOAP-ENV:Server</faultcode>
 <faultstring>String was not recognized as a valid DateTime.</faultstring>
-<detail>
 <af:legacy_detail>String was not recognized as a valid DateTime.</af:legacy_detail>
 <af:exception message =" String was not recognized as a valid DateTime. " type =" System.FormatException " />
 </detail>
 </SOAP-ENV:Fault>
 </SOAP-ENV:Body>
 </SOAP-ENV:Envelope>

1) Can anyone explain how the system checks if the DateTime value is valid?
2) Is there an elegant, reusable way to perform this functionality?

I have created a new Item, using an OnGet method to return todays parts, but this is a lot of effort for a relatively simple requirement. It is not reusable and it does not address why the above approach does not work.

Many thanks,
Martin.

  • Hello,

    I don't see anything in particular that would cause the date in that AML to be recognized as invalid. The system does check for a particular format which you can generate from a .NET DateTime object by using DateTime.ToString("yyyy-MM-ddTHH:mm:ss"); .

    Would you be able to share your method code for this onBeforeGet event? I think the issue may be coming from the structure of that method itself. Typically an onBeforeGet is done for validation and query modification purposes. The this object passed into this event is an Item that represents the query about to be performed. To modify this query, you can simply update and return the this object without applying it. You can see an example of how to replace the string "yesterday" with a query to search on yesterday's date in the Gist below.

    https://gist.github.com/cgillis-aras/a925e60fcf77d9b0a582ea703f1eab8f

    In this Gist, I've also modified the AML you provided slightly to use the between condition rather than using a gt and a lt on two different properties.

    To answer your second question about reusability, it would be possible to create a custom search mode that allowed strings like "yesterday" or "tomorrow" to be passed in to date properties. You can also look at the sample code in this forum post to see how another user implemented relative date searches. Note that the user in that post modified a core file in the codetree which we do not recommend doing. However, you could use the code provided there in a custom search mode to achieve a similar result.

    I hope the sample code and information helps! Let me know if you have any follow up questions.

    Chris

    Christopher Gillis

    Aras Labs Software Engineer