Menu

How to order by a date an array in a simple rule format

Help
Romain
2021-02-08
2021-02-11
  • Romain

    Romain - 2021-02-08

    Hello,

    I have a simple decision table with 4 conditions and return a String value.
    2 columns are of Date type to express a rule validity interval. Start date and end date.
    It works well with the calculation rule : determinate the first rule who matchs with the 3 given parameters.

    I want to simplify the 2 Date columns with only one Date column. And the calculation rule would be : determinate the last rule who matched order by date.
    How can I write an order by clause on a condition column and return only the last element of an array ?

    For example, with the file in attachment, with the parameters offerName=Offer1 and departmentNumber=1 and date=15/10/2022 , I want to return the value of the rule R3 « Assurance 3 »

    Any help would be appreciate.
    Kind regards,

     
  • Elena Kosolapova

    Hello Romain,

    The best practice would to keep C4 condition. But if there is a need to cut C4 condition, we came up with the following solutions (see excel file attached):

    a. The first solution is to re-order the rules by C3 condition: rules with the latest start date should go first. (see giveAssureur_solution1 table)
    b. The second solution is to return the array of custom elements having Start Date and Assurance Name fields, then order this array by Offer Date , and take the Assurance Name value of the first element.(see giveAssureur_solution2 and giveAssureur_solution2_main tables)
    c. There is a more compact Decision table type in OpenL: Smart Rules. Start Date and End Date columns may be united under the same condition and expression min <= date &&date < max will be automatically generated for it. Pay attention that the right border is excluded from the range in the expression.(see giveAssureur_solution3 table)
    Note: currently there is a bug with functionality of SmartRules max/min columns working with LocalDate datatype. The workaround would be to import "java.time.LocalDate" via Environment table. The fix will be available in future release.

    Best Regards,
    Alena.

     
  • Romain

    Romain - 2021-02-11

    Hi Elena,

    Thanks for your time.
    The solution 2 seems the best for our use cases. So If I understood well, I have to call the function in the Spreadsheet table as this :

    // Java code
    ruleEngine.giveAssureur_solution2_main("offer", "10", "2021-01-01");
    

    I prefer solution 2 because solution 1 has the inconvenient to keep in mind the order of data. And solution 3, the end date must always be entered by the business users.

    Thanks again

     

Log in to post a comment.