# How to detect a change in a Managed Object with an EPL APP?

**URL:** <https://community.cumulocity.com/t/how-to-detect-a-change-in-a-managed-object-with-an-epl-app/1267>\
**Category:** Forum\
**Tags:** analytics, Streaming-Analytics-Apama, cumulocity\
**Created:** [December 18, 2022, 12:47pm UTC](https://community.cumulocity.com/t/how-to-detect-a-change-in-a-managed-object-with-an-epl-app/1267 "2022-12-18T12:47:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Harrison\_Pace](https://dub1.discourse-cdn.com/flex005/user_avatar/community.cumulocity.com/harrison_pace/32/2961_2.png) [@Harrison\_Pace](https://community.cumulocity.com/u/Harrison_Pace)\
**Post date:** [December 18, 2022, 12:47pm UTC](https://community.cumulocity.com/t/how-to-detect-a-change-in-a-managed-object-with-an-epl-app/1267/1 "2022-12-18T12:47:01Z")

</div>

#### What product/components do you use and which version/fix level are you on?

Cumulocity  
**1011.0.17**

#### Is your question related to the free trial, or to a production (customer) instance?

Production

#### What are you trying to achieve? Please describe it in detail.

Using an EPL App, I would like to monitor the inventory for changes in Managed Objects with the fragment `IsMatterDevice{}`.

In this object I have a fragment which I would like extract attributes from, totalise them and update another fragment in the object, each time the managed object changes.

I believe I need to subscribe to the ManagedObject events and monitor the `NOTIFICATION_UPDATED` parameter. But it’s not clear to me how I do that? I was hoping for some code samples? Also I expect there to be a lot of there devices (1000s), so the solution should be scalable…

For reference, I’m happy to update this value anytime any fragment changes in the managed object.

Thanks

---

<div class="post-metadata">

**Author:** ![Sharon\_Golden](https://avatars.discourse-cdn.com/v4/letter/s/43a26b/32.png) [@Sharon\_Golden](https://community.cumulocity.com/u/Sharon_Golden)\
**Post date:** [December 19, 2022, 5:13pm UTC](https://community.cumulocity.com/t/how-to-detect-a-change-in-a-managed-object-with-an-epl-app/1267/2 "2022-12-19T17:13:43Z")

</div>

Hi Harrison,  
In EPL you can monitor for changes in Managed Objects with something like the following (and for your changes you just need the update section)

```auto
...
    // Subscribe for notification for managed objects
    monitor.subscribe(ManagedObject.SUBSCRIBE_CHANNEL);

    // Listen for notifications for managed objects
    on all ManagedObject() as managedObject {
        if managedObject.isCreate() {
            log "ManagedObject created" at INFO;
        }
        else if managedObject.isUpdate() {
            log "ManagedObject updated" at INFO;
        }
    }

    // Listen for notifications on deleted managed objects
    on all ManagedObjectDeleted() as managedObjectDeleted {
        log "ManagedObject deleted" at INFO;
    }
...

```

You can find this information in the Apama documentation  
Search for “Receiving update notifications” it is under the section “The Cumulocity IoT Transport Connectivity Plug-in”

[Receiving update notifications (softwareag.com)](https://documentation.softwareag.com/apama/v10-11/apama10-11/apama-webhelp/index.html#page/apama-webhelp%2Fco-ConApaAppToExtCom_cumulocity_receiving_update_notifications.html)

I see you’re on version 10.11, Are you using Cumulocity Cloud or Edge? If it is Cumulocity Cloud, 10.11 is quite an old version and we would recommend updating to a newer version

With regards scalability, especially if there are 1000’s of devices, Please note that if you expect a large number of events at any one time, that the outgoing calls from Apama to Cumulocity will be processed in serial through the httpClient until the later version of 10.15.

Another thing to keep an eye out for is potential cycles. If this could be an issue perhaps something you need to consider are separate child Managed Objects, of different types, for the calculated value. Otherwise when you update the calculated value, you could end up in a situation where you get another notification of change.

Hope this helps,  
Regards,  
Sharon

---

<div class="post-metadata">

**Author:** ![Felix.Schaede](https://avatars.discourse-cdn.com/v4/letter/f/c4cdca/32.png) [@Felix.Schaede](https://community.cumulocity.com/u/Felix.Schaede)\
**Post date:** [December 20, 2022, 8:13am UTC](https://community.cumulocity.com/t/how-to-detect-a-change-in-a-managed-object-with-an-epl-app/1267/3 "2022-12-20T08:13:51Z")

</div>

Hi Harrison,

you will find the fragment `IsMatterDevice{}` in the params dictionary of the ManagedObject. So, following Sharon’s suggestions, you should find the updates to the ManagedObjects with :

```auto
using com.apama.cumulocity.ManagedObject;

monitor ListenOnManagedObjects {
	action onload() {
		log "Loaded monitor ListenOnManagedObjects" at INFO;
		monitor.subscribe(ManagedObject.SUBSCRIBE_CHANNEL);
		on all ManagedObject() as mo {
			if (mo.isUpdate() and mo.params.hasKey("IsMatterDevice")) {
				log "# ManagedObject" + mo.toString() at INFO;
				//Add your code here
			}
			
		}
	}
}

```

Felix

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/flex005/user_avatar/community.cumulocity.com/system/32/31990_2.png) [@system](https://community.cumulocity.com/u/system)\
**Post date:** [June 18, 2023, 8:14am UTC](https://community.cumulocity.com/t/how-to-detect-a-change-in-a-managed-object-with-an-epl-app/1267/4 "2023-06-18T08:14:36Z")

</div>

Closed on June 18, 2023, 8:14am UTC

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