Skip to Content
Technical Articles

Using Vocabulary Rules to Build Reusable Formulas in SAP Cloud Platform Business Rules

In continuation to my previous blog, in this blog I will explain how to further venture into decision orchestration capabilities to create, manage and work with formula rules that can be reused during business rules modelling.

Some initial key information first:

  • Vocabulary Rule is the term used for reusable rule or formula rule.
  • Rule can be used in expression modelling and as normal rule.
  • Rule used in expression modelling are called vocabulary rules and will be executed during expression evaluation.
  • Rule that is used for expression modelling can also be used as normal rule by adding them to ruleset. Such rules would be executed as part of ruleset evaluation.
  • Cyclic dependency will be determined during deploy time and fails the deployment if you have modelled rules in cyclic fashion. For Example: You have used Rule1 as expression in same Rule1 or you have used Rule1 as expression in Rule2 and used Rule2 as expression in Rule1

Vocabulary rule is not a new modelling concept. It comes with the sole intension to ease the modelling experience for reusable use cases like for defining complex formulas that can be reused over and again while modelling expressions, for SaaS scenarios where predefined standard rules can be shipped as part of the base project which can be reused for further rule modelling etc.

Let us now see (a) how to model vocabulary rules and use them in expression modelling, and (b) how to invoke such rules and see the change in the output.

Modelling vocabulary rule

  • There is no special way as how you model vocabulary rules
  • Vocabulary rule as modelled as any general rule

  • All you need is include the rule in Vocabulary of the Ruleset
    • As soon as you add the rule to vocabulary, it becomes available as suggestions while expression modelling
    • You can include both text and decision table rule as vocabulary rule.

 

 

 

  • Vocabulary rule can be used as formula and can also be included in the ruleset as main rule (see the screenshot below).

  • You though have to be careful while using it in both categories because it may lead to cyclic dependency. Cyclic dependencies will be identified during deployment.
    • Recommendation is to use rule either for formula rule or for normal rule.
  • In both the cases, there is something to keep in mind from execution stand-point:
    • Be it vocabulary rule or main rule, they will be executed during the course of rule service invocation – and each invocation would need an input data object. It is the responsibility of business rules developer to ensure that input data object is either provided via rule-service vocabulary or ruleset vocabulary.
      • In case where you have included rule ONLY as vocabulary rule (which means you have added it as vocabulary of the ruleset and not as main rules) then you need to ensure that data objects (both conditions and results) on which vocabulary rule is modelled must be declared via Included Data Objects in Vocabulary of Ruleset.
  • In case where you have included the vocabulary rule also under Rules section of the ruleset, then you need to ensure that data objects (both conditions and results) on which vocabulary rule is modelled must be declared in Vocabulary of Ruleservice.

Bottomline is – you need to ensure that input and output data objects of all the rules in the ruleset (whether under Vocabulary or Rules section) must be declared either via rule-service or ruleset vocabulary

Invoking Vocabulary Rule

  • As said, vocabulary rule is no special rule. It can be executed as part of the normal rule service invocation API both in Neo and CF environment. The only difference is when you add the vocabulary rule as intermediate rule (by adding it only to vocabulary of the ruleset) then the rule execution will happen internally (during expression evaluation) and result would be consumed without giving you any output explicitly.

This completes the overview on decision orchestration capabilities in SAP Cloud Platform Business Rules. It strengthens the overall experience of using the tool and covers many more use cases especially with interleaving decision points.

3 Comments
You must be Logged on to comment or reply to a post.
  • Hello Archana,

     

    This sounds like a great feature! 🙂

    However, when I try to implement what is explained in this document in my Neo account, I always get the attached error message. I tried every conceivable combination of data-object placement/definition but with no avail.

    I try to implement a very basic example, with a decision table containing two condition columns and one one result column. I want the 2nd column to be based on a vocabulary rule.

    When I arrange the input such that the 2nd column is not inspected (due to not matching the 1st one), then there is no problem. But when the 2nd column is processed, the below error message is returned.

    Is there some bug preventing me from successfully using vocabulary rules, or am I doing something wrong?

    Please help

    Thanks,

    Tom Zamir

     

    {
      "error": {
        "code": "bpm.rulesruntime.internalservererror",
        "message": "Error encountered during processing of request",
        "details": []
      }
    }
    • Hello Tom,

      Error messages would be enhanced in upcoming releases to show more meaning messages. This error usually comes when you have something wrong in modelling which validation could not discover. Can you please raise a ticket and attach the project in the ticket or write an email to me.

       

      Thanks,

      Archana