Menu

How to make Decision Table Return Multiple Values?

Help
2015-12-15
2018-03-26
  • James Dekker

    James Dekker - 2015-12-15

    How can one use OpenL Tablets to make a decision table return multiple values?

    For example,

    If the input is an integer named price and there's a range (min and max), how can the decision table output two strings?

    Attached is the decision table that I am using in Excel (.xls) file format.

    Again, thank you for creating such a great product!

     

    Last edit: James Dekker 2015-12-15
  • Sergey Zyrianov

    Sergey Zyrianov - 2015-12-15

    James, please see example in the attachment.

    The way how you did serves the different use case when you might want different returns from one rule. This way it will return only one value either from RET1 or RET2. This is useful when you want to define a bit different return formulas or mix and match multiple value types in one rule.

    When you want to return multiple values from one rule you need to wrap them into one compound type. The same way you usually do with any other service. To business analysts I wouldn't recommend to explain the mechanichs behind but just ask to use syntax "new [compound result] ([ordered list of actual values])"

     

    Last edit: Sergey Zyrianov 2015-12-15
  • James Dekker

    James Dekker - 2015-12-16

    Sergey,

    Thank you very much! This is exactly what I was looking for!

    Long live OpenL Tablets!

    Cheers,

    James

     
  • Sergey Zyrianov

    Sergey Zyrianov - 2015-12-17

    James, thanks! :)

     
  • NISALA PERERA

    NISALA PERERA - 2016-01-28

    I need to return an array of objects relaed to this ttype of senario.

    I have tried several ways according to "new [compound result] ([ordered list of actual values])".

    Could you please send an example to return TravelRecommendation[], that would be highly appriciated.

     
  • Laurent

    Laurent - 2018-02-02

    Hi,

    Is it possible to return several data type with Rules.
    like requested by Nisala

     
  • Sergey Zyrianov

    Sergey Zyrianov - 2018-02-04

    Hi Laurent,

    Yes, it's possible to return multiple results from a rule. Could you be more specific what eactly you're trying to do?

    The best way is to create an example and use it as a part of the question. There are a lot of ways how you can work with arrays, multiple results, etc. We motivate our users to try to solve a task themselves before asking for help.

     
  • Laurent

    Laurent - 2018-02-05

    Hi Sergey,

    thanks for your quick answer.
    I want the system returning 2 results for R101 & 102 in the attached file.
    With trace it seems the 2 rules are found but there is only one result returned.

    Thanks
    Laurent

     
  • Sergey Zyrianov

    Sergey Zyrianov - 2018-02-05

    Hi Laurent,

    Please take a look into the attached Excel with your example and also a simplified version of the same table. The only difference in the original table is usage of 'CRET' column which stands for collect return.

    Please note that it's our latest feature since 5.20. Before you would need to use 2 different Decision tables and Action column with list object to achieve the same result.

    Thanks,
    Sergey

     

    Last edit: Sergey Zyrianov 2018-02-05
  • Laurent

    Laurent - 2018-02-05

    Good perfect Sergey !! works fine. Thanks

    Is there a way to build a test table with such Rules ?

    Regards
    Laurent

     
  • OpenL Tablets

    OpenL Tablets - 2018-02-06

    Hi, Laurent.

    Currently, there is no simple way to test rules which return an array of complex types. I put this feature in a backlog, so it will be implemented soon. I expect to delivery this feature in 2...3 weeks.
    If it is urgent, I can find a workaround for You.

    Regards,
    Yury.

     
  • Elena

    Elena - 2018-02-06

    Hi, Laurent.

    Some clarifications in addition to the previous answer. Currently we have the following approach of testing rules that return an array : test each element using the syntax
    _ res _ [i].< attribute name >
    (in Ref guide see "Specifying Data for Aggregated Objects" chapter, this syntax ia valid for Test tables as well).
    I've prepared an example for your rule, see test PropertyMappingTest1. In this option the test case is written in a single row.
    Ragarding a feature mentioned: we are going to implement the possibility to write this test case in a multiple rows like in example PropertyMappingTest2.

    Thanks, Elena

     
  • Elena

    Elena - 2018-02-06

    Hi again, Laurent!)

    I forgot to share with you one more option - to define expected objects via Data tables! The peculiarity is that we can not do this in Test table, so we are using Data tables and refer to the values via keys (the key can be the first attribute, in your case the first attribute do not have unique values thats why I'm using PK). Plz see my example PropertyMappingTest3.

    I would be interested to hear some feedback which option (PropertyMappingTest1, PropertyMappingTest2 or PropertyMappingTest3) appeal to you more. Your feedback is very important for me to understand how to improve our product.

    Thanks, Elena

     

    Last edit: Elena 2018-02-06
  • Laurent

    Laurent - 2018-02-07

    Thanks a lot Elena.

    Test works fine.
    I've tested to deploy (with Demo package) my Excel file, but empty results is returned with PropertyMapping rule. (no error neither) I've tested with SOAP UI.
    On the other hand test performed with Webstudio works fine and results list is ok.
    Is there something wrong with demo package ?

    Thanks
    Laurent

     
  • OpenL Tablets

    OpenL Tablets - 2018-02-08

    Hi Laurent,

    Thank you for pointing on this issue. I found that if the arguments of rules are capitalized, then REST service cannot match input JSON parameters on arguments in rules. To fix this issue you have to rename input arguments like "PDMObjectType" to "pdmObjectType". Anyway this issue will be fixed ASAP.

    SOAP request is working correctly:

    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:def="http://DefaultNamespace" xmlns:con="http://context.rules.openl.org">
       <soapenv:Header/>
       <soapenv:Body>
          <def:PropertyMapping>
             <def:PDMObjectType>ADAP-Assy</def:PDMObjectType>
             <def:PDMProp>Status</def:PDMProp>
          </def:PropertyMapping>
       </soapenv:Body>
    </soapenv:Envelope>
    

    Regards,
    Yury.

     
  • Laurent

    Laurent - 2018-02-09

    Thanks Yury, it works

     
  • romg

    romg - 2018-03-26

    Hello,

    I can't manage to use this collect function from java code. In my interface class I tried to bind my method output to java list, collection and array, with no success. And I can't find anything related to this function in the documentation.

    I systematically have this exception thrown:

    Exception in thread "main" org.openl.syntax.exception.CompositeOpenlException: Binding Error(s):
    Error: Incompatible method return type with 'CRET1' header.
    

    Is it implemented "rules engine" package?

    Thanks and regards,

    Jérôme

     
  • romg

    romg - 2018-03-26

    Hello again,

    Of course it was a mistake on my side... Works much better by declaring the return type not only with the "collect" keyword, but also as an array:

    SimpleRules Collect String[] TstRule(String tstInputString)
    

    Instead of:

    SimpleRules Collect String TstRule(String tstInputString)
    

    List can then be retrieved in java code as an array.

    Jérôme

     

Log in to post a comment.