Axeda Groovy Script: Copy Data Item value to Asset Property value

    This Groovy script takes any dataitem values and writes them to properties of the same name - if they exist. The rule to call this script needs to be a data trigger such as:


    If: some condition

    Then: ExecuteCustomObject("CopyParameters")


    The script uses the default context that contains an asset (device) and the default parameter dataItems that contains the current reported dataitems (from an agent)


    import com.axeda.drm.sdk.user.User
    import groovy.lang.PropertyValue
    import com.axeda.drm.sdk.device.DevicePropertyFinder
    import com.axeda.drm.sdk.device.Property
    import com.axeda.drm.sdk.device.PropertyType
    import com.axeda.drm.sdk.device.DeviceProperty "Executing groovy script for device: " + context?.device?.serialNumber
    if (dataItems != null)
    { "** Data Items **"
      // show data item values
      dataItems?.each {di -> "dataitem: ${} = ${di.value} = ${di.timestamp}"
      def dataItemMap = [:]
      dataItems.each{ dataItemMap[] = it }
      DevicePropertyFinder dpf = new DevicePropertyFinder (context.context)
      dpf.type = PropertyType.DEVICE_TYPE =
      DeviceProperty dp = dpf.findOne()
      List<Property> props = dp.getProperties()
      props.each {Property prop->
        if (dataItemMap.containsKey( {
          prop.value = dataItemMap[].value?.toString()
          // "Setting ${} to ${dataItemMap[].value?.toString()}"