How do I add comment lines to a business rule authored in Business Action Language

2.8k views Asked by At

I am using JRules to author business rules. I want to add comments to the rules as shown in the very simple example below. I realise there is a documentation section for the rule but that is not what I require

// comments needed here

definitions 
set 'an existing customer' to a customer
where the category of 'an existing customer' is "gold"

if 
the city of 'an existing customer' is "London"

then
give a 5% discount to 'an existing customer'

else
// and more comments needed here
give a 10% discount to 'an existing customer'

Clearly, using the usual c++ and c# double forwardslash // will not work in the example above, so my question is how are comments added to rules in BAL.

3

There are 3 answers

0
Tito On BEST ANSWER

Unfortunately you cannot add comments in rules. The rules are supposed to be self explanatory if the verbalization is good.

But you can use the documentation feature,if you want to document the business justification for each of the rules.

0
Damien On

You can do it but it means a hell lot of customization. So forget it
And it would be feasible only via browser interface, not Eclipse.
Just because you will be cheating.

How to do it:
Ready?... Steady?...
You need to recreate your own RTS (teamserver) web interface! if it sounds like too much effort then stop reading :)
Using the API, you can retrieve the rules from RTS (database) the there is (as mention in Tito's answer) a documentation attached to any rule.
So you can handle the display of your rule and add the comment accordingly.
Of course you need to find a way to position the comment correctly in the rule
Line number could do the trick.
This is for the display...
Ten when you save the rule (by clicking a lovely button that you will have coded to do the actual saving) you need to remove the comments (and know where they are for the next time you want to display the rule) and save both the rule body and the documentation attached.

Sounds crazy? One client done it and I was working on this :) but we didn't modify the rule body. Almost everything but the rule body.

This will take you months, inpependently to the number of people working on it, I'm afraid.

To sum up: Can you do it, yes!
Does the implementation worth the effort? NO WAY!!!

Will this feature be available in the next version? NO! As Tito mentioned a rule should be self-explainatory.

Sorry :(

1
toK On

There is a simple workaround:

You can create 2 static virtual methods in your BOM: one commenting the conditions and one for the actions.

In the case of conditions:

  • Create a static method that takes a parameter String and return a boolean
  • Verbalize it like this "// {0}" (without quotes)
  • In the B2X, make it return true
  • Then, you can comment a condition with //"your_condition" and ...

In the previous example:

if 
the city of 'an existing customer' is "London" and
// "blablabla" and
the age of 'an existing customer' is greater than 18

then ...

Since the method returns true, it won't affect the test. It has to be surrounded by "and", not "or".

In the case of actions:

  • Create a static method that takes a parameter String and return void
  • Verbalize it like this "// {0}" (without quotes)
  • In the B2X, add "return;"
  • Then, you can comment an action with //"your_action" ;

In the previous example:

else
// "and more comments needed here" ;
give a 10% discount to 'an existing customer' ;