Forum Discussion

rneuber1's avatar
rneuber1
Ideator I
9 years ago

Relative date search

Hi all, we had the requirement to be able to search for relative Dates, for example: "Modified within the last week" or "Due within the next 30 days". Aras (9.4 in our case) does not support that, so we've hacked it ourselves, maybe it can be useful for others, too. For our users it is sufficient to use it within AML queries, so there is no fancy UI needed. With the patch described below it is possible to use '@today(offset)' to write queries like: <modified_on condition="ge">@today(-1)</modified_on> (Modified since yesterday) or
<and>
   <due_date condition="ge">@today()</due_date>
   <due_date condition="le">@today(7)</due_date>
</and>
(due next week) To achieve this, simply edit Innovator\Client\javascript\search_container.js and add the following snippet after line 642:
// Search for any @{n} parameter in Aml.
var re = new RegExp();

// Check for relative dates: @today{-20} will be replaced with the date of 20 days before today
if (/@today\((-?\d+)\)/g.test(searchAml))
	{
		var reDate = new RegExp("@today\\((-?\\d+)\\)","g");

		var m;
		while (m = reDate.exec(searchAml))
		{
			var diff =  parseInt(m[1]) ;
			var foundString = m[0];
			var today = new Date();
			var relDate = new Date();
			var toff = relDate.getTimezoneOffset();
			relDate.setDate(today.getDate() +  diff);
			relDate.setHours(0,-1 * toff,0,0);
			var nd = relDate.toISOString();
			nd = nd.substr(0,nd.length - 5); // Remove .000Z
			searchAml = searchAml.replace(foundString, nd);
		}
Any comments are welcome. \Ralf

4 Replies

  • For Aras 11 it would most likely go into 'Innovator\Client\javascript\SearchParameterizedHelper.js' but I haven't tested it yet.
    • christopher_gillis's avatar
      christopher_gillis
      New Member

      Hi amitosh,

      I'd recommend checking out my response to this forum post for some other examples of how to implement relative date searches. My suggestions there were tested in 11.0 SP15. 

      Chris