AnsweredAssumed Answered

Update sysfilter from Request Event

Question asked by ewan.sadie.sanlam on Mar 4, 2019
Latest reply on Mar 5, 2019 by chewa03

Can I update req.urlParameters.sysfilter before the request is sent to resource, eg. to add a date filter to a database first resource via Request Event?

I created the below Request Event but it does not seem to "apply" the filter

 

 

 

if (req.verb === 'GET' && req.resourceName === 'bookings' ) {
var today = new Date();
var tomorrow = new Date();
tomorrow.setDate(today.getDate()-1);
var date = tomorrow.getDate();
var month = tomorrow.getMonth();
var year = tomorrow.getFullYear();
var yearMonthDay = pad(year) + "-" + pad(month) + "-" + pad(date) + "T00:00:00";
//var params = JSON.parse(req.urlParameters);
var hasData = JSON.stringify(req.urlParameters.sysfilter, null, 2)
log.debug("THE DATE: " + yearMonthDay + " -- ");

if(req.urlParameters.sysfilter){
//if(params.sysfilter.match(/BookingDate/).length === 0) {
if(hasData.indexOf("BookingDate") > -1){
//log.debug("HAS BOOKINGDATE");
var sFilter = req.urlParameters.sysfilter + ',greaterequal(BookingDate:timestamp(' + yearMonthDay + '))';
req.urlParameters.sysfilter = sFilter;
}

}
else
{
req.urlParameters.sysfilter = 'greaterequal(BookingDate:timestamp(' + yearMonthDay + '))';
}

log.debug("sysFilter: " + req.urlParameters.sysfilter);


}

function pad(n) {
return n<10 ? '0'+n : n;
}

Outcomes