How to retrieve a declared metadata in an action part from a JBoss BRMS 6 rule?
Environment
- Red Hat JBoss BRMS (BRMS) 5.x, 6.x
Issue
- There is a situation to use a declared metadata in
thenpart from a rule. How to use the declared metadata in the action section of a rule? - How to retrieve a declared metadata in an action part from JBoss BRMS 6 rule?
Resolution
Declaring Metadata may be assigned to several different constructions in Drools: fact types, fact attributes and rules. Drools uses the at sign ('@') to introduce metadata, and it always uses the form: @metadata_key( metadata_value ). So it can be defined and retrieved in a rule as follows:
rule "Hello"
@aKey(Hello World)
when
eval( true )
then
System.out.println(kcontext.getRule().getMetaData().get("aKey"));
end
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.
Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.
