Add tag hisOnWrite and add value 

hisOnWritewriteLastKnownValueOrNull


writeLastKnownValueOrNull
(his, rec) => do
  lastKnownVal: 0
  getLastKnownVal: () => do
      if(lastKnownVal != 0) return lastKnownVal
      if(rec.has("hisEnd")) do
        hisEnd: rec->hisEnd
        start: hisEnd - 1hour
        hisRecs: readById(rec->id).hisRead(start..hisEnd)
        hisGrid: hisRecs.addMeta({dummy})
        val : null
        if(hisGrid != null) do
          val = hisGrid[hisGrid.size - 1]["v0"].as(1)
        end
        return val
      end
      else do
        return null
      end
  end
  return his.map r => r.set("val", if (r->val == 0) getLastKnownVal() else r->val)
end


  • No labels