Fluent Commerce Logo
Docs
Sign In

Update an order attribute and trigger an orchestration via user action

How-to Guide

Author:

Fluent Commerce staff

Changed on:

9 Apr 2024

Key Points

  • This article gives System Integrator (SI) Partners and Businesses a high-level idea of where new features can be built on top of the OMS reference solution to support the customer's requirement within Fluent OMS.
  • This idea/solution will provide a new feature where the User can enter/update an Order Attribute value via user Action and trigger an orchestration.
  • The source code can be used by using Rule SDK and in the default Mystique Manifest.

Steps

Step arrow right iconUse Case

As a user, I want to update a specific field to make the order class type.  The value is a String value and can be used for the downstream process.  

Step arrow right iconDesign Solution Overview

In the order entity, capture the CLASS value in the attribute level and this can be updated via user action on the OMX UI.  For modification, it should have the ability to pre-populate the existing value into the text field.

To prove the user action will trigger the orchestration when the button is submitted, it will call another ruleset to change the order Status.


Step arrow right iconTechnical Design Overview

To support the business solution design, the following technical areas need to be enhanced:

  • A new custom rule (by using Rule SDK):
    • `UpdateClassOrder`
  • Create a new Ruleset in HD Order workflow (
    `ChangeOrderClass`
    )
  • Add 2 new rules into Order workflows
    • `SET_ORDER_HOLD`
    • `UpdateClassOrder`
  • Update Mystique Manifest in Setting -
    `fc.mystique.manifest.oms.fragment.ordermanagement`

Step arrow right iconCustom Rule

A custom Rule need to be added: 

`UpdateClassOrder`

Property

Value

Plugin name

<yourPluginName>

Rule API Client

GraphQL

Rule Info Description

Add or Update an Event Attribute of CLASS name and of type STRING to the current Entity.

Supported Entities

ORDER

Input Parameters

No input parameters are required.

Event Attributes

Attribute Name

Description

`classValue`

accepts String value which will be saved into the attribute.


1package <PackageName>.util;
2
3/**
4 * Use this class to define all the constants you will use in your rules!
5 */
6public final class Constants {
7
8    private Constants() { }
9
10    public static final String ATTRIBUTE_NAME_PARAMETER_NAME = "name";
11
12    public static final String ATTRIBUTE_VALUE_PARAMETER_NAME = "value";
13
14    public static final String ATTRIBUTE_TYPE_PARAMETER_NAME = "type";
15
16    public static final String EVENT_NAME_PARAMETER_NAME = "eventName";
17
18    public static final String ORDER_CLASS_NAME = "CLASS_NAME";
19
20    public static final String ORDER_CLASS_TYPE = "STRING";
21
22    public static final String ORDER_CLASS_VALUE = "classValue";
23
24}
25

Language: java

Name: Setup constant Strings:

Description:

Create 3 Strings in Constants:
ORDER_CLASS_NAME
ORDER_CLASS_TYPE
ORDER_CLASS_VALUE


1package <PackageName>.rule;
2
3import com.fluentretail.rubix.foundation.graphql.RANDY6.mutations.UpdateOrderMutation;
4import com.fluentretail.rubix.foundation.graphql.type.AttributeInput;
5import com.fluentretail.rubix.foundation.graphql.type.UpdateOrderInput;
6import com.fluentretail.rubix.rule.meta.EventInfo;
7import com.fluentretail.rubix.rule.meta.EventAttribute;
8import com.fluentretail.rubix.rule.meta.ParamString;
9import com.fluentretail.rubix.rule.meta.RuleInfo;
10import com.fluentretail.rubix.v2.context.Context;
11import com.fluentretail.rubix.v2.rule.Rule;
12import com.fluentretail.rubix.v2.util.RuleUtils;
13import lombok.extern.slf4j.Slf4j;
14
15import java.util.Collections;
16
17import static <PackageName>.util.Constants.*;
18@RuleInfo(
19        name = "UpdateClassOrder",
20        description = "Add or Update an Event Attribute value for the CLASS name to the current Entity.",
21        accepts = {
22                @EventInfo(entityType = "ORDER")
23        }
24)
25
26@EventAttribute(name = ORDER_CLASS_VALUE )
27
28@Slf4j
29public class UpdateClassOrder implements Rule  {
30    @Override
31    public void run(Context context) {
32
33        AttributeInput attributeInput = AttributeInput.builder()
34                .name(ORDER_CLASS_NAME)
35                .type(ORDER_CLASS_TYPE)
36                .value(context.getEvent().getAttribute(ORDER_CLASS_VALUE))
37                .build();
38
39        UpdateOrderInput updateOrderInput = UpdateOrderInput.builder()
40                .id(context.getEntity().getId())
41                .attributes(Collections.singletonList(attributeInput))
42                .build();
43
44        UpdateOrderMutation mutation = UpdateOrderMutation.builder()
45                .input(updateOrderInput)
46                .build();
47
48        context.action().mutation(mutation);
49    }
50}
51

Language: java

Name: UpdateClassOrder Java Class

Description:

Add or Update an Event Attribute value for the CLASS name to the current Entity.

Step arrow right iconWorkflow ORDER HD changes

Create a new Ruleset

`SET_ORDER_HOLD`
:

1  {
2            "name": "SET_ORDER_HOLD",
3            "type": "ORDER",
4            "subtype": "HD",
5            "eventType": "NORMAL",
6            "rules": [
7                {
8                    "name": "<Accountid>.commonv2.ChangeStateGQL",
9                    "props": {
10                        "status": "R_HOLD"
11                    }
12                }
13            ],
14            "triggers": [
15                {
16                    "status": "BOOKED"
17                },
18                {
19                    "status": "R_HOLD"
20                }
21            ],
22            "userActions": []
23        },
24        
25//. Ensure that R_HOLD is listed on the statuses list within the workflow.

Language: json

Name: Rulset SET_ORDER_HOLD in Order workflow

Description:

A simple ruleset that updates the order status.


Create a new Ruleset

`ChangeOrderClass`
:

1 {
2            "name": "ChangeOrderClass",
3            "description": "Change Order Class Type",
4            "type": "ORDER",
5            "subtype": "HD",
6            "eventType": "NORMAL",
7            "rules": [
8                {
9                    "name": "<Accountid>.<packageName>.UpdateClassOrder",
10                    "props": {}
11                },
12                {
13                    "name": "<Accountid>.commonv2.SendEventGQL",
14                    "props": {
15                        "eventName": "SET_ORDER_HOLD"
16                    }
17                }
18            ],
19            "triggers": [
20                {
21                    "status": "BOOKED"
22                }
23            ],
24            "userActions": [
25                {
26                    "context": [
27                        {
28                            "label": "Change Order Class",
29                            "type": "SECONDARY",
30                            "modules": [
31                                "adminconsole"
32                            ],
33                            "confirm": true
34                        }
35                    ],
36                    "attributes": [
37                        {
38                            "name": "classValue",
39                            "label": "my class Value",
40                            "type": "STRING",
41                            "mandatory": false
42                        }
43                    ]
44                }
45            ]
46        },

Language: json

Name: ruleset ChangeOrderClass

Description:

This rule set will display the user action button in the secondary level if the order status is BOOKED status. Upon submission, it will call

`UpdateClassOrder`
to update the order attribute and send an event to
`SET_ORDER_HOLD`

Step arrow right iconMystique Manifest Change

Go to Setting:

`fc.mystique.manifest.oms.fragment.ordermanagement`


1"props": {
2"title": "{{orderById.ref}} - {{orderById.status}}",
3"actions": {
4    
5    "secondary": [
6        
7            {
8                "type": "userAction",
9                "name": "ChangeOrderClass",
10                "overrides": {
11                    "classValue": {
12                        "defaultValue": "{{orderById.attributes.byName.CLASS_NAME}}"
13                    }
14                }
15            }
16        ...
17        
18// note: ensure that the query are getting the order attributes.

Language: json

Name: add default value into classValue field in fc.mystique.manifest.oms.fragment.ordermanagement

Description:

[Warning: empty required content area]



Step arrow right iconResult

A User Action drawer is displayed to allow user to enter Class Value:

No alt provided

Enter a value. for example: FASTMOVING.

No alt provided

After saved, the value is saved into order attribute:

No alt provided

The order status is set to R_HOLD (as part of the ruleset orchestration)

No alt provided

Open the User action again, the saved value is displayed on the text field.

No alt provided
Fluent Commerce staff

Fluent Commerce staff

Copyright © 2024 Fluent Retail Pty Ltd (trading as Fluent Commerce). All rights reserved. No materials on this docs.fluentcommerce.com site may be used in any way and/or for any purpose without prior written authorisation from Fluent Commerce. Current customers and partners shall use these materials strictly in accordance with the terms and conditions of their written agreements with Fluent Commerce or its affiliates.

Fluent Logo