cancel
Showing results for 
Search instead for 
Did you mean: 

use Date Picker to filter the page - MDK

0 Kudos

I have created a filter page. In that I have added a date picker. I want to filter using the date picker in mdk. is there any way to do that ?

Thank You

Accepted Solutions (1)

Accepted Solutions (1)

Jitendra_Kansal
Product and Topic Expert
Product and Topic Expert

In MDK 5.2 release, we introduced supporting Rules for Result Object in Filter page, you can customize the filter values return out of Date Picker selection. You have to use the createFilterCriteria to create FilterCriteria object and finally return an array.

For example, i am calling this Rule to the Result of a page where i have DatePicker FormCell control.
This returns list of SalesOrders created on a selected date.

export default function FilterResults_SO(context) {
    let datePickerValue = context.evaluateTargetPath('#Page:FormCell_SO/#Control:DatePicker/#Value');
    var d = new Date(datePickerValue);
    var result = d.getFullYear() +  "-" + ("0"+(d.getMonth()+1)).slice(-2) + "-" + ("0" + d.getDate()).slice(-2);
    var result1 = `${result}T00:00:00`;
    var result2 = `${result}T23:59:59`;
    var filterQuery = `CreatedAt ge datetime'${result1}' and CreatedAt le datetime'${result2}'`;
    result1 = [filterQuery];
    let filterCriteria = context.createFilterCriteria(context.filterTypeEnum.Filter, undefined, undefined, result1, true);
    let filterResults = [filterCriteria];
    return filterResults;

Of course, you need to adjust the rule according to your scenario.

0 Kudos

Hi Jitendra Kansal,

Your code for date filter is working absolutely fine. But I am facing another issue with it. In the filter page I also have a filter property. I was returning that as well in the result section.

But the moment I add the rule for the date filter, the above command gets removed. is there a way to do it in a single rule.

Thank You

fjcarrasco
Active Participant

kohlisamvaran76

You need to return the value of all filters in your new rule. Example:

 let filterResults = [];

    let result = context.evaluateTargetPath('#Page:IncomeHist_Filter/#Control:SortBy/#Value');
    filterResults.push(result);
    result = context.evaluateTargetPath('#Page:IncomeHist_Filter/#Control:ListPickerFormCellBank/#FilterValue');
    filterResults.push(result);
    result = context.evaluateTargetPath('#Page:IncomeHist_Filter/#Control:ListPickerFormCellProof/#FilterValue');
    filterResults.push(result);
    result = context.evaluateTargetPath('#Page:IncomeHist_Filter/#Control:ListPickerFormCellColType/#FilterValue');
    filterResults.push(result);
    result = context.evaluateTargetPath('#Page:IncomeHist_Filter/#Control:ListPickerFormCellRep/#FilterValue');
    filterResults.push(result);

    if (filter) {
        result = `Budat ge datetime'${fromIncDate}' and Budat le datetime'${toIncDate}'`;
        let simplePropertyFilterResult = context.createFilterCriteria(context.filterTypeEnum.Filter, 'Budat', 'Budat', [result], true);
        filterResults.push(simplePropertyFilterResult);
    }

    return filterResults;

Answers (0)