0

I have a requirement to set a new property (example: unique ID) to each and every rule and access it from action part of the respective rules during the execution. For example: If the age of person is more than 18 then set the output to the ID of the rule.

(Here ID should come from the new property being added.)

I am using IBM ODM 8.5. Please suggest what are all the ways get unique ID from business rules?

In the B2X mapping of virtual method, I printed the rule.properties map using instance.getRule().properties. I was expecting custom properties and all other rule properties. However, the properties map only had a handful of following six:

key: ilog.rules.business_name value: test score

key: ilog.rules.package_name value: check score

key: requestorMail value:

key: status value: new

key: ilog.rules.package value: check_score

key: ilog.rules.group value: check_score.test_score

kc2001
  • 5,008
  • 4
  • 51
  • 92
user2968583
  • 3
  • 1
  • 6

2 Answers2

2

You can customize rule model with Model extension and add your custom property (YOUR_PROPERTY_NAME) to the rule artefact.

You can acces this by adding a virtual method (static method in the BOM! don't use a xom! simply add it with the BOM editor) verbalized YOUR_VERBALISATION.

  • In the method implementation (B2X), you can get the value with the instance.getRule().getPropertyValue("YOUR_PROPERTY_NAME"); (instance is a runtime variable containing the IlrRuleInstance of the current Rule)
  • In the action part use YOUR_VERBALISATION to call the method.
Akram GARGOURI
  • 205
  • 1
  • 10
  • Thank you very much. I am able to access the property (as per verbalisation). But I need to access the value of this property in the action part of the rule. For example: If I set the Unique ID property of the rule (on the right side) to a string "abcd". then I should be able to write the rule as "then set the output to the unique id of the rule" so that the value of output is set to "abcd". Right now I am getting it as NULL. – user2968583 Nov 12 '13 at 14:08
  • Try this `(String)instance.getRule().getPropertyValue("YOUR_PROPERTY_NAME")` – Akram GARGOURI Nov 12 '13 at 15:00
  • Unfortunately it does not work. I am still getting null. My rule looks like -----------------then set the output of Result to the unique id of the name of this rule ; – user2968583 Nov 12 '13 at 15:39
  • and return instance.getRule().getPropertyValue("BRL_ID").toString(); gives the below IlrUserRuntimeException ...........Target method: public java.lang.String java.lang.Object.toString() at call to 'translation.helper._checkId_B2X_String(java.lang.String)' – user2968583 Nov 12 '13 at 15:43
  • I used to restart and clean my workspace to get new properties of the custom model extension. Use the casting with `(String)` instead of `toString()` (i don't know why toString() didn't work) – Akram GARGOURI Nov 12 '13 at 15:54
  • One more question please, is there any information needs to be filled in "Custom Properties" section of the Virtual Class? – user2968583 Nov 12 '13 at 16:11
  • instance.getRule().properties gives only a few rule properties, not all. Custom properties are also not in the properties map. Is a plugin required? – user2968583 Nov 12 '13 at 21:35
  • You don't need any plugin i worked with them recently. Make sure that your custom property has extractable="true" (in the .brmx model extension) If it still not working, you can post you .brmx and code? – Akram GARGOURI Nov 13 '13 at 08:15
  • Thanks. The custom property has extractable=true. I am sharing the code/brmx here: http://pastie.org/private/51xynoulkwvytmj2cq – user2968583 Nov 13 '13 at 09:02
  • i don't have dev environnement now, i'll see how my code worked by tomorrow. – Akram GARGOURI Nov 13 '13 at 09:39
  • I had an additional Annotation in the brmx file. Removing it fixed the problem. Thank you! – user2968583 Nov 13 '13 at 19:29
0

Another approach you could use is to create your set of variables (Variable Set). Within a Variable Set you define:

  1. The name of the variable
  2. The type of the variable
  3. The verbalization for this variable
  4. (Optional) The initial value for this variable

It's easy to create and it's accessible to any part of you Rule Application or Module.

Hope this helps.