Rule Parameters
Author:
Fluent Commerce
Changed on:
28 Sept 2023
Overview
Rule Parameters, also known as properties or props, and the configuration time inputs to the Rule.
Rule Parameters should be considered always required. Optional inputs to a Rule should usually be managed via Event Attributes.
Rule Parameters
Author:
Fluent Commerce
Changed on:
28 Sept 2023
Overview
Rule Parameters, also known as properties or props, and the configuration time inputs to the Rule.
Rule Parameters should be considered always required. Optional inputs to a Rule should usually be managed via Event Attributes.
Key points
- There are 4 Parameter types available to declare on Rules:
- String Parameters
- Integer Parameters
- Enum Parameters
- Time Period Parameters
- Also, on this page, see how to implement Multi-value Parameters
String Parameters
The
`@ParamString`
`String`
It contains 3 properties:
- - the Name of the Parameter. This is Required.
`name`
- - the Description of the Parameters. This is Required.
`description`
- - this is the Default Value of the Parameter. This is Optional.
`defaultValue`
Property Name | Description | Required | Default Value |
| The name of the rule parameter. This becomes the key name used in the
| Y | |
| A helpful text describing the parameter. This is important meta data for use within the Workflow Builder UI and the Plugin GET API. | Y | |
| A default value if the parameter is not set. | N |
1@ParamString(name = "productCatalogueRef", description = "The reference to the Product Catalogue", defaultValue = "FCRG:PC:MASTER")
Language: java
Name: Here is an example declaration of @ParamString:
Description:
[Warning: empty required content area]Integer Parameters
The
`@ParamInteger`
`Integer`
It contains 5 properties:
Property Name | Description | Required | Default Value |
| The name of the rule parameter. This becomes the key name used in the
| Y | |
| A helpful text describing the parameter. This is important meta data for use within the Workflow Builder UI and the Plugin GET API. | Y | |
| The minimum value allowed to be entered for the rule parameter. | N |
|
| The maximum value allowed to be entered for the rule parameter. | N |
|
| A default value if the parameter is not set. | N |
|
1@ParamInteger(name = "ParamInt1", description = "Parameter Int 1", min = 0, max = 9, defaultValue = 0)
Language: java
Name: Here is an example declaration of @ParamInteger:
Description:
[Warning: empty required content area]Enum Parameters
The
`@ParamEnum`
`Enum`
It contains 4 properties:
Property Name | Description | Required | Default Value |
| The name of the rule parameter. This becomes the key name used in the
| Y | |
| A helpful text describing the parameter. This is important meta data for use within the Workflow Builder UI and the Plugin GET API. | Y | |
| This is the Enum class providing the available options to be selected. | Y | |
| A default value if the parameter is not set. | N |
1// Define an Enum use either in the same Java file as the Rule, or in a separate file within your Plugin Project:
2enum YesNoEnum {
3 YES, NO
4}
5
6@ParamEnum(name = "DoSomething", description = "Select YES or NO to doing something", options = YesNoEnum.class, defaultValue = YesNoEnum.YES)
Language: java
Name: Here is an example declaration of @ParamEnum:
Description:
[Warning: empty required content area]Time Period Parameters
The
`@ParamTimePeriod`
`Integer`
It contains 5 properties:
Property Name | Description | Required | Default Value |
| The name of the rule parameter. This becomes the key name used in the
| Y | |
| A helpful text describing the parameter. This is important meta data for use within the Workflow Builder UI and the Plugin GET API. | Y | |
| The minimum value allowed to be entered for the rule parameter. | N |
|
| The maximum value allowed to be entered for the rule parameter. | N |
|
| A default value if the parameter is not set. | N |
|
1@ParamTimePeriod(name = "delaySeconds", description = "Delay value in seconds", min = 0, max = 9, defaultValue = 5)
Language: java
Name: Here is an example declaration of @ParamTimePeriod:
Description:
[Warning: empty required content area]Multi-value Parameters
Rules can receive complex objects, such as Arrays or a JSON object, as Parameter inputs.
For example, you may need to receive an object containing a number of fields, or an array of Strings, Integers, or any other Objects.
Typically, we recommend using a standard String Parameter which receives a Setting name which references a Setting in the platform.
It is up to the Rule logic to handle the correct parsing of this complex type.
For example, let's say you want to provide a list of Virtual Catalogue References for querying Virtual Positions within the Rule. You could create a Rule Parameter for the Setting Name, such as
`acme.sourcing.multi-channel.catalogues`
1{
2 "virtualCatalogueRefs": [
3 "VC:ATS:ECOMMERCE",
4 "VC:ATS:MARKETPLACE"
5 ]
6}
Language: json
Name: Example
Description:
[Warning: empty required content area]1@RuleInfo(name = "FulfilFromMultiSources", description = "Fulfils from any available positions in multiple Virtual Catalogues configured in setting {cataloguesSetting}")
2@ParamString(name = "cataloguesSetting", description = "The Setting name holding the list of Virtual Catalogue References to include in the search")
3public class FulfilFromMultiChannelSources implements Rule {
4 @Override
5 public <C extends Context> void run(C context) {
6 String cataloguesSetting = context.getProp("cataloguesSetting");
7
8 // Note: the `getSetting` method is not provided, but encapsulates querying the GraphQL Settings API.
9 Optional<VirtualCataloguesSetting> setting = getSetting(context, cataloguesSetting).as(VirtualCataloguesSetting.class);
10
11 if(setting.isPresent()) {
12 // Continue Sourcing...
13 } else {
14 // Note: the `logOnce` method is not provided, but encapsulates the `context.action().log()` action.
15 logOnce(context, VirtualCataloguesSetting.class, "No Catalogues config found at '%s'", cataloguesSetting);
16 }
17 }
18
19 @Data
20 @AllArgsConstructor
21 private static final class VirtualCataloguesSetting {
22 String[] virtualCatalogueRefs;
23 }
24}
Language: java
Name: The Rule could be implemented as follows:
Description:
[Warning: empty required content area]