Get and display rule names in messages
As a best practice, Guidewire recommends that you get and display rule names in messages. So, following the Guidewire best practices for rule names helps you identify specific rules in messages to users, in print statements for testing, and in log messages. The alphabetic beginning of a rule identifier helps you find the rule set or parent rule that contains the rule. The numeric ending helps you determine the order of a rule in a rule set or parent rule.
For example,
you want to test a producer code validation rule, PCV01000 - No producer code roles.
The identifier portion of the rule name begins with PCV. That identifies the rule
as a member of the ProduceCodeValidationRules
rule set. The identifier ends with 01000.
That indicates that rule is near the beginning of the rule set. The rule
has the following definition.
PCV01000 - No producer code roles
Rule Conditions:
producerCode.ProducerCodeRoles.Count == 0
Rule Actions:
producerCode.rejectField("ProducerCodeRoles", null, null, "loadsave",
"A role is required for producer code" + producerCode.Code + "."
)
As written, the rejection message that
the rule action displays makes it difficult to determine exactly which
rule caused an update to fail. To help identify the specific rule in
the rejection message, use the actions.getRule().DisplayName
property to include the identifier portion of the rule name in the message.
Rule Actions:
producerCode.rejectField("ProducerCodeRoles", null, null, "loadsave",
"A role is required for producer code " + producerCode.Code +
". Rule: " + actions.getRule().DisplayName.substring(8)
)
By including the rule display name in the rule action, users see the following statement in the Validation window when the rule action executes.
A role is required for producer code ACME235. Rule: PCV01000
String
values into display keys.