Class isc.wf.REST Extends %CSP.REST { Parameter CONTENTTYPE = "application/json"; Parameter CHARSET = "UTF-8"; Parameter UseSession As Integer = 1; Parameter CONVERTINPUTSTREAM = 1; XData UrlMap [ XMLNamespace = "http://www.intersystems.com/urlmap" ] { } /// End session ClassMethod logout() As %Status { #dim %session As %CSP.Session set sc = %session.Logout(1) set %session.EndSession = 1 quit sc } /// Test method ClassMethod test() As %Status { write "{""Status"": ""OK""}" quit $$$OK } /// Get tasks. Supports pagination. /// count - number of records to get /// maxId - latest id, leave empty to start from the begining /// set sc = ##class(isc.wf.REST).getTasks() ClassMethod getTasks(count = 100, maxId = "") As %Status { #dim sc As %Status = $$$OK #dim isFirst As %Boolean = $$$YES &sql( DECLARE C1 CURSOR FOR SELECT TOP :count %ID, IsNew, Task->%Priority, Task->%Subject, Left(Task->%Message, 100), TimeCreated, RoleName INTO :id, :isNew, :priority, :subject, :message, :timeCreated, :role FROM EnsLib_Workflow.Worklist WHERE (UserName = USER) AND ((Task->TaskStatus_AssignedTo IS NULL) OR (Task->TaskStatus_AssignedTo = UserName)) AND ((%ID < :maxId) OR (:maxId IS NULL)) ORDER BY %ID DESC) &sql(OPEN C1) &sql(FETCH C1) write:((SQLCODE=0) || (SQLCODE=100)) "[" while (SQLCODE = 0) { if isFirst { set isFirst = $$$NO } else { write ",",! } write "{""id"":""", id,""",", """isNew"":",$case(isNew, $$$YES: "true", :"false"),",", """priority"":",priority,",", """subject"":""", $zcvt(subject,"O", "JSON"),""",", """message"":""", $zcvt(message,"O", "JSON"),""",", """timeCreated"":""", $tr(timeCreated, " ", "T") _ "Z",""",", """role"":""", role,"""}" &sql(FETCH C1) } if (SQLCODE'=100) { set sc = $$$ERROR($$$SQLError, SQLCODE, $g(%msg)) } else { write "]" } &sql(CLOSE C1) quit sc } /// Get one task /// set sc = ##class(isc.wf.REST).getTask("318||dev") ClassMethod getTask(id) As %Status { #dim sc As %Status = $$$OK &sql( SELECT %ID, IsNew, Task->%Priority, Task->%Subject, Task->%Message, TimeCreated, RoleName, Task, Task->%Actions, Task->%FormFields INTO :id, :isNew, :priority, :subject, :message, :timeCreated, :role, :task, :actions, :formFields FROM EnsLib_Workflow.Worklist WHERE (%ID = :id) AND (UserName = USER)) if (SQLCODE = 0) { write "{""id"":""", id,""",", """isNew"":",$case(isNew, $$$YES: "true", :"false"),",", """priority"":",priority,",", """subject"":""",$zcvt(subject,"O", "JSON"),""",", """message"":""",$zcvt(message,"O", "JSON"),""",", """timeCreated"":""", $tr(timeCreated, " ", "T") _ "Z",""",", """role"":""",role,""",", """actions"":""",actions,""",", """formFields"":{" merge fieldValues = ^Ens.MessageBodyD(task, "%FormValues") set fieldCount = $case(formFields, "":0, :$l(formFields, ",")) for field = 1:1:fieldCount { set fieldName = $p(formFields, ",", field) continue:fieldName="" set fieldValue = $g(fieldValues(fieldName)) // Special handlers // "$$$Handler": {"myLink":"link","myImg":"img"} if fieldName = "$$$Handler" { write """",$zcvt(fieldName,"O", "JSON"),""":",fieldValue } else { write """",$zcvt(fieldName,"O", "JSON"),""":""",$zcvt(fieldValue,"O", "JSON"),"""" } write:(field