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
   <due_date condition="ge">@today()</due_date>
   <due_date condition="le">@today(7)</due_date>
(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
Parents Reply Children
No Data