0

I need to be able to create an event processing rule that when you add a new device, you take a string value from one fragment (e.g.: c8y_Hardware.imei) and use that string to populate another fragment (e.g: c8y_Mobile.imei). So the new device would then have the same value in both c8y_Hardware.imei and c8y_Mobile.imei.

We have attempted setting up the appropriate CEP rules, but they are not working (they do compile and save).

insert into UpdateManagedObject

    select

        m.id as id,

        {
            "c8y_Mobile.imei", getString(m,"c8y_Hardware.imei")
        } as fragments

    from 

        ManagedObjectCreated as m 

    where

        getString(m,"c8y_Hardware.imei") != "";

Any guidance on where we are messing up our syntax would be greatly appreciated.

1 Answers1

1

It should be: m.managedObject.id as id.

Usually you would also get an error on compile but it can be that the streams also have an id so that it technically works in CEP. You should be able to check if it triggers on the debug stream and see the id that has been set.

Same applies for all other Cumulocity streams. The streams itself e.g. ManagedObjectCreated or AlarmUpdated etc. are not the objects directly. They have always a property like in this case managedObject or for AlarmUpdated it is alarm. This property is the actual payload.

The helper methods like getString are written in a way that you can pass either the payload or the full stream object so there it does not matter.

TyrManuZ
  • 2,039
  • 1
  • 14
  • 23
  • I made that change. Thank you. Unfortunately, it still does not work. Is there a way to debug this? The windows on the right side of the UI are not very helpful. – Boyd Machtolff Mar 27 '19 at 22:08
  • Hmm, for me it is working. As you only listen to ManagedObjectCreated you should check if the IMEI is also set on creation and not added afterwards with a PUT. The debugging on the right side only shows you outputs of statements. So if your statement never triggers you won't see anything – TyrManuZ Mar 28 '19 at 15:52