# Json path event trigger

**URL:** <https://developer.sailpoint.com/discuss/t/json-path-event-trigger/8317>\
**Category:** SHF Discussion and Questions\
**Tags:** event-triggers\
**Created:** [February 17, 2023, 5:18pm UTC](https://developer.sailpoint.com/discuss/t/json-path-event-trigger/8317 "2023-02-17T17:18:07Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![clstromgren](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/clstromgren/32/2284_2.png) [@clstromgren](https://developer.sailpoint.com/discuss/u/clstromgren)\
**Post date:** [February 17, 2023, 5:18pm UTC](https://developer.sailpoint.com/discuss/t/json-path-event-trigger/8317/1 "2023-02-17T17:18:07Z")

</div>

I have an existing event trigger I am trying to add additional criteria to and am looking for some ideas on the json path. Basically right now, the criteria is:

```auto
$.changes[?(@.attribute == "accountingUnit" || @.attribute == "legalEntity")]

```

and I am trying to add in filter criteria to only send event if positionCode is also included in the event, but either accountingUnit OR legalEntity changes with

```auto
$.changes[?(@.attribute == "positionCode" && (@.attribute == "accountingUnit" || @.attribute == "legalEntity"))]

```

Here is a sample event i have been testing with:

```auto
{
        "identity": {
            "id": "2c9180838222dcdc0182265f16427ce5",
            "name": "21097371",
            "type": "IDENTITY"
        },
        "changes": [
            {
                "attribute": "positionDescription",
                "oldValue": "FABRICATION SHIFT C OPERATOR",
                "newValue": "LAMINATING SHIFT D OPERATOR"
            },
            {
                "attribute": "positionShortDescription",
                "oldValue": "303017",
                "newValue": "375573"
            },
            {
                "attribute": "legalEntity",
                "oldValue": "530-G2423",
                "newValue": "530-G5426"
            },
            {
                "attribute": "accountingUnitDescription",
                "oldValue": "G.Goole (265) - LAMINATING SHIFT C",
                "newValue": "G.Goole (265) - LAMINATING SHIFT D"
            },
            {
                "attribute": "positionCode",
                "oldValue": "303017",
                "newValue": "375573"
            }
        ],
        "_metadata": {
            "triggerType": "fireAndForget",
            "triggerId": "idn:identity-attributes-changed",
            "invocationId": "4c50578a-aa63-422f-9220-9bbbfa3541ae"
        }
    }

```

For comparison, i have done something similar on a different event and it seems to work OK.

filter is

```auto
$.requestedItems[?(@.operation != "Remove" && (@.id == "e10bf8643dd8471396880d7e7e51a489" || @.id == "cea271971fe44e5abf09ea38ae876fe7"))]

```

and the event is

```auto
{
        "accessRequestId": "19176f8595224785872896ac7d25ead0",
        "requestedFor": {
            "id": "2c9180878222dc6701822b2845b11ef8",
            "name": "Chandru, Swathi",
            "type": "IDENTITY"
        },
        "requestedItems": [
            {
                "id": "e10bf8643dd8471396880d7e7e51a489",
                "name": "GHR Security Administrator - Firefighter",
                "description": "HRIT App Sec use only - This role grants firefighter access to perform Application Security functions in GHR.",
                "type": "ACCESS_PROFILE",
                "operation": "Add",
                "comment": "Need access to handle error BODs created as part of monthly user purge activity in IFS"
            }
        ],
        "requestedBy": {
            "type": "IDENTITY",
            "id": "2c9180878222dc6701822b2845b11ef8",
            "name": "21039278"
        },
        "_metadata": {
            "callbackURL": "https://koch.api.identitynow.com/beta/trigger-invocations/85f92719-50a9-4631-aede-9d5c9e740b86/complete",
            "secret": "eba943f7-bda5-4682-9d1d-adcd32c9a902",
            "triggerType": "requestResponse",
            "triggerId": "idn:access-request-pre-approval",
            "invocationId": "85f92719-50a9-4631-aede-9d5c9e740b86"
        }
    }

```

Appreciate any ideas anyone has

Thank you,  
Caleb

---

<div class="post-metadata">

**Author:** ![colin\_mckibben](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/colin_mckibben/32/37182_2.png) [@colin\_mckibben](https://developer.sailpoint.com/discuss/u/colin_mckibben)\
**Post date:** [February 17, 2023, 7:51pm UTC](https://developer.sailpoint.com/discuss/t/json-path-event-trigger/8317/2 "2023-02-17T19:51:59Z")

</div>

Try this.

`$[?($.changes.*.attribute contains "positionCode")].changes[?(@.attribute == "legalEntity" || @.attribute == "accountingUnit")]`

It gets tricky when you try to check if multiple attributes both exist at the same time. We have to get crafty. The first part of the above expression creates a list of attribute names, and then checks if `positionCode` is one of the names.

`$.changes.*.attribute` produces this result:

```json
[
	"positionDescription",
	"positionShortDescription",
	"accountingUnit",
	"accountingUnitDescription",
	"positionCode"
]

```

`$[?($.changes.*.attribute contains "positionCode")]` will match your `positionCode` while also returning the original input object.

```json
[
	{
		"identity": {
			"name": "21097371",
			"id": "2c9180838222dcdc0182265f16427ce5",
			"type": "IDENTITY"
		},
		"changes": [
			{
				"newValue": "LAMINATING SHIFT D OPERATOR",
				"attribute": "positionDescription",
				"oldValue": "FABRICATION SHIFT C OPERATOR"
			},
			{
				"newValue": "375573",
				"attribute": "positionShortDescription",
				"oldValue": "303017"
			},
			{
				"newValue": "530-G5426",
				"attribute": "accountingUnit",
				"oldValue": "530-G2423"
			},
			{
				"newValue": "G.Goole (265) - LAMINATING SHIFT D",
				"attribute": "accountingUnitDescription",
				"oldValue": "G.Goole (265) - LAMINATING SHIFT C"
			},
			{
				"newValue": "375573",
				"attribute": "positionCode",
				"oldValue": "303017"
			}
		],
		"_metadata": {
			"triggerId": "idn:identity-attributes-changed",
			"triggerType": "fireAndForget",
			"invocationId": "4c50578a-aa63-422f-9220-9bbbfa3541ae"
		}
	}
]

```

So the first part of the expression guarantees that `positionCode` is one of the attributes, while returning the original object. Now we are free to check if one of the other two attributes is also present.  
`$[?($.changes.*.attribute contains "positionCode")].changes[?(@.attribute == "legalEntity" || @.attribute == "accountingUnit")]`

```json
[
	{
		"newValue": "530-G5426",
		"attribute": "accountingUnit",
		"oldValue": "530-G2423"
	}
]

```

Because the expression found an item that matches, it is considered a success and the trigger will send the event. If at any point the expression doesn’t match anything, the trigger won’t fire. For example, if `positionCode` wasn’t present, the result of the expression would be:

```json
[]

```

And the trigger won’t fire.

---

<div class="post-metadata">

**Author:** ![clstromgren](https://sea1.discourse-cdn.com/sailpoint/discuss/user_avatar/developer.sailpoint.com/clstromgren/32/2284_2.png) [@clstromgren](https://developer.sailpoint.com/discuss/u/clstromgren)\
**Post date:** [February 17, 2023, 8:12pm UTC](https://developer.sailpoint.com/discuss/t/json-path-event-trigger/8317/3 "2023-02-17T20:12:04Z")

</div>

> [@colin\_mckibben](#):
>
> `$[?($.changes.*.attribute contains "positionCode")].changes[?(@.attribute == "legalEntity" || @.attribute == "accountingUnit")]`

Awesome, that worked! Appreciate the assist and thank you very much for explaining it out too. Have a good weekend

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/sailpoint/original/2X/f/f2136700ed5e3703e0b85e02f6be799dacca7735.png) [@system](https://developer.sailpoint.com/discuss/u/system)\
**Post date:** [July 19, 2023, 2:24pm UTC](https://developer.sailpoint.com/discuss/t/json-path-event-trigger/8317/4 "2023-07-19T14:24:21Z")

</div>

Closed on July 19, 2023, 2:24pm UTC


