WorkFlow Trigger Condition: JSONpath to check if multiple attributes have changed

Hi Team,

I am trying to create a workflow in which changes in 2 identity attributes of the user should cause workflow to get triggered.Could you please confirm if this json path is correct else which is the correct one?Below is the condition i am adding as the filter to trigger Identity Attribute change.
$.changes[?(@.attribute == “jobTitle” && @.attribute == “department”)]

Or condition is working fine but AND condition is not working and workflows are not getting triggered with this event. Kindly could you please help me with this?

Thanks,
Sindhu

Using the && operator in this scenario won’t work because you are trying to see if a single property, @.attribute, is both “jobTitle” and “department”. This can’t happen, as properties can only have one value at any given time.

I think what you are trying to do is fire an event if both the jobTitle and the department change in a single Identity Attribute Change event. Unfortunately, I don’t think this is possible using JSONpath. What you can do is set the trigger filter to only fire if the jobTitle attribute changes, and then use a comparison operator to see if the department attribute also changed.

Hi @colin_mckibben ,

If we have to use multiple attributes changes to trigger event in Workflow, then from the above solution we can take one attribute to fire the event but to check the other attribute value change for example manager of identity has changed or not , how shall we use compare string operator? As the Compare string operator compares with static value of a string, can you help here…

1 Like

I just had an epiphany :bulb:

Although you can’t use && in a filter to check that multiple attributes are present in a single payload, you can take a different route that I have used several times for other scenarios. Consider the following payload.

{
  "identity": {
    "id": "ee769173319b41d19ccec6cea52f237b",
    "name": "john.doe",
    "type": "IDENTITY"
  },
  "changes": [
    {
      "attribute": "department",
      "oldValue": "sales",
      "newValue": "marketing"
    },
    {
      "attribute": "manager",
      "oldValue": {
        "id": "ee769173319b41d19ccec6c235423237b",
        "name": "william.wilson",
        "type": "IDENTITY"
      },
      "newValue": {
        "id": "ee769173319b41d19ccec6c235423236c",
        "name": "ed.engineer",
        "type": "IDENTITY"
      }
    },
    {
      "attribute": "email",
      "oldValue": "[email protected]",
      "newValue": "[email protected]"
    }
  ]
}

If you want to only trigger an event when both the “department” and the “manager” have changed, you can use the following JSONpath expression.

$[?($.changes[?(@.attribute == "department")] size 1)][?($.changes[?(@.attribute == "manager")] size 1)]

Update: A simpler expression is $[?($.changes[?(@.attribute == "department" || @.attribute == "manager")] size 2)] .

Let’s break this down.

  1. $[?($.changes[?(@.attribute == "department")] size 1)] will return the entire JSON object IF “department” is an attribute in the changes array. We need the size 1 to ensure that there is exactly one attribute with “department”.
  2. Since the first part of the expression returns the entire object if “department” is an attribute, then we can apply the same expression, but look for the “manager” attribute: [?($.changes[?(@.attribute == "manager")] size 1)]. If “manager” exists, then once again it will return the entire object, which is considered a successful JSONpath query.

You can continue to chain together these filter expression to have a virtually infinite list of attributes (or any other value) you want to check exists in the same payload. For example, if you want to check if the attribute email changed OR both the department AND manager changed, you could use this expression:

$[?(($.changes[?(@.attribute == "email")] size 1) || ($.changes[?(@.attribute == "department" || @.attribute == "manager")] size 2))]

The size 2 operation implements the AND (&&) logic by making sure both department and manager are present .

3 Likes

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.