Problem
When using task definition arguments to provide input to a rule post-deployment, the argument values may appear as null or empty. For example, a task definition designed to collect system metrics and send an email based on input arguments fails to populate the argument values unless updated manually via the UI.
Diagnosis
The issue occurs because the task hasn’t executed yet, and the rule does not automatically pick up the default value unless explicitly coded to handle this scenario. This happens because the logic to retrieve the default value must be defined in the custom rule.
Solution
To address this, update your rule to handle cases where the task definition argument is null or empty by retrieving its default value. For instance, if your task definition argument is defined as follows:
<Inputs>
<Argument defaultValue="%%USER_DATA_EMAIL%%" helpKey="Email Recipients" name="emailRecipient" type="string">
<Prompt>Email recipients to send the email to (csv list)</Prompt>
</Argument>
</Inputs>
Include the following logic in your rule to retrieve the argument value:
// ************************** Task Parameter ********************************** //
String emailRecipient = (Util.isNotNullOrEmpty(taskDefinition.getString("emailRecipient"))) ? taskDefinition.getString("emailRecipient") : "";
if (Util.isNullOrEmpty(email)) { // INFO: Upon post-deployment the value above is null so we need to grab the default value
for (Argument arg : taskDefinition.getSignature().getArguments()) {
if ("emailRecipient".equalsIgnoreCase(arg.getName())) {
email = arg.getDefaultValue();
break;
}
}
}
// ************************** Task Parameter ********************************** //
This ensures that if the task definition argument is null post-deployment, the rule fetches and applies the default value automatically.