Creating an alarm from custom objects

I have an ER that checks for a file hint and executes a custom object that reads the uploaded file. The groovy script reads the file, and does some validation; I, then, have to create an alarm if the validation fails. How do I create an alarm by custom objects? Following is what I tried  to create an alarm (the name "FileInvalid" is in Alarm Definitions):

    DevicePropertyFinder dpf = new DevicePropertyFinder(Context.create())

    dpf.type = PropertyType.DEVICE_TYPE

    dpf.id = context.device.id

    dp = dpf.findOne()

    AlarmEntry alarmEntry = new AlarmEntry(context, dp, "FileInvalid", 5)

    alarmEntry.store()

 

easy

Hello, all you would have to do here is

------

def userContext = Context.create()

AlarmEntry alarmEntry = new AlarmEntry(userContext , context.device, "FileInvalid", 5)

alarmEntry.store()

-------

the 'context' automatic variable is a handle to the trigger that caused the rule. From that you can get the device reference, which is all you need. I'm not sure what you were trying to do with DeviceProperty but it was unneccessary.

This simple three-liner should do the trick!

Thank you. Worked like a

Thank you. Worked like a charm. 

Is there a way to add notes as well?