Workflow samples
Basics
Section titled “Basics”Suggested code sample
Section titled “Suggested code sample”First, you must create the webservice object:
OKMWebservices ws = OKMWebservicesFactory.newInstance(host);Then should login using the method “login”. You can access the “login” method from webservice object “ws” as is shown below:
ws.login(user, password);At this point you can use all the Workflow methods from “workflow” class as is shown below:
ws.workflow.registerProcessDefinition(is);For most examples, it has been used the Purchase workflow sample.
Methods
Section titled “Methods”registerProcessDefinition
Section titled “registerProcessDefinition”Description:
| Method | Return values | Description |
|---|---|---|
| registerProcessDefinition(FileStream fs) | void | Registers a new workflow. |
Example:
using System;using System.Collections.Generic;using System.Linq;using System.Text;using com.openkm.sdk4csharp;using System.IO;
namespace OKMRest{public class Program{static void Main(string[] args){String host = "http://localhost:8080/openkm";String username = "okmAdmin";String password = "admin";OKMWebservice ws = OKMWebservicesFactory.newInstance(host);
try{ws.login(user, password);FileStream fs = new FileStream("E:\\Purchase.par",FileMode.Open);ws.workflow.registerProcessDefinition(fs);fs.Dispose();}catch (Exception e){System.Console.WriteLine(e.ToString());}}}}deleteProcessDefinition
Section titled “deleteProcessDefinition”Description:
| Method | Return values | Description |
|---|---|---|
| deleteProcessDefinition(long pdId) | void | Deletes a workflow. |
The parameter pdId value is a valid workflow process definition.
Example:
using System;using System.Collections.Generic;using System.Linq;using System.Text;using com.openkm.sdk4csharp;using System.IO;
namespace OKMRest{public class Program{static void Main(string[] args){String host = "http://localhost:8080/openkm";String username = "okmAdmin";String password = "admin";OKMWebservice ws = OKMWebservicesFactory.newInstance(host);
try{ws.login(user, password);long pdId = 5; // Valid workflow process definitionws.workflow.deleteProcessDefinition(pdId);}catch (Exception e){System.Console.WriteLine(e.ToString());}}}}getProcessDefinition
Section titled “getProcessDefinition”Description:
| Method | Return values | Description |
|---|---|---|
| getProcessDefinition(long pdId) | void | Returns a workflow process definition. |
The parameter pdId value is a valid workflow process definition.
Example:
using System;using System.Collections.Generic;using System.Linq;using System.Text;using com.openkm.sdk4csharp;using com.openkm.sdk4csharp.bean;
namespace OKMRest{public class Program{static void Main(string[] args){String host = "http://localhost:8080/openkm";String username = "okmAdmin";String password = "admin";OKMWebservice ws = OKMWebservicesFactory.newInstance(host);
try{ws.login(user, password);long pdId = 1; // Valid workflow process definitionProcessDefinition pd = ws.workflow.getProcessDefinition(pdId);System.Console.WriteLine(pd);}catch (Exception e){System.Console.WriteLine(e.ToString());}}}}runProcessDefinition
Section titled “runProcessDefinition”Description:
| Method | Return values | Description |
|---|---|---|
| runProcessDefinition(long pdId, String uuid, List |
ProcessInstance | Executes a workflow on some node. |
The parameter pdId value is a valid workflow process definition.
The parameter uuid can be any document, mail, folder or record UUID.
The parameter values are form element values needed for starting the workflow ( not all workflows need form values for starting ).
Example:
using System;using System.Collections.Generic;using System.Linq;using System.Text;using com.openkm.sdk4csharp;using com.openkm.sdk4csharp.bean;using com.openkm.sdk4csharp.bean.form;
namespace OKMRest{public class Program{static void Main(string[] args){String host = "http://localhost:8080/openkm";String username = "okmAdmin";String password = "admin";OKMWebservice ws = OKMWebservicesFactory.newInstance(host);
try{ws.login(user, password);long pdId = 8041; // Some valid workflow process definition idList<FormElement> feList = new List<FormElement>();Input price = new Input();price.name = "price";price.value = "1000";feList.Add(price);TextArea textArea = new TextArea();textArea.name = "description";textArea.value = "some description here";feList.Add(textArea);ws.workflow.runProcessDefinition(pdId, "7aa523e0-06cf-4733-b8c8-cc74d8b2716d", feList);}catch (Exception e){System.Console.WriteLine(e.ToString());}}}}findAllProcessDefinitions
Section titled “findAllProcessDefinitions”Description:
| Method | Return values | Description |
|---|---|---|
| findAllProcessDefinitions() | List |
Retrieves a list of all registered workflows definitions. |
Example:
using System;using System.Collections.Generic;using System.Linq;using System.Text;using com.openkm.sdk4csharp;using com.openkm.sdk4csharp.bean;
namespace OKMRest{public class Program{static void Main(string[] args){String host = "http://localhost:8080/openkm";String username = "okmAdmin";String password = "admin";OKMWebservice ws = OKMWebservicesFactory.newInstance(host);
try{ws.login(user, password);foreach (ProcessDefinition pd in ws.workflow.findAllProcessDefinitions()){System.Console.WriteLine(pd);}}catch (Exception e){System.Console.WriteLine(e.ToString());}}}}findProcessInstances
Section titled “findProcessInstances”Description:
| Method | Return values | Description |
|---|---|---|
| findProcessInstances(long pdId) | List |
Retrieves a list of all process instances of some registered workflows definition. |
The parameter pdId value is a valid workflow process definition.
Example:
using System;using System.Collections.Generic;using System.Linq;using System.Text;using com.openkm.sdk4csharp;using com.openkm.sdk4csharp.bean;
namespace OKMRest{public class Program{static void Main(string[] args){String host = "http://localhost:8080/openkm";String username = "okmAdmin";String password = "admin";OKMWebservice ws = OKMWebservicesFactory.newInstance(host);
try{ws.login(user, password);// Get all workflow definitionsforeach (ProcessDefinition pd in ws.findAllProcessDefinitions()){System.Console.WriteLine("WF definition: "+pd);// Get all process of some workflow definitionforeach (ProcessInstance pi in ws.workflow.findProcessInstances(pd.id)){System.Console.WriteLine("PI: "+pi);}}}catch (Exception e){System.Console.WriteLine(e.ToString());}}}}findLatestProcessDefinitions
Section titled “findLatestProcessDefinitions”Description:
| Method | Return values | Description |
|---|---|---|
| findLatestProcessDefinitions() | List |
Retrieves a list of the last workflows definitions. |
Example:
using System;using System.Collections.Generic;using System.Linq;using System.Text;using com.openkm.sdk4csharp;using com.openkm.sdk4csharp.bean;
namespace OKMRest{public class Program{static void Main(string[] args){String host = "http://localhost:8080/openkm";String username = "okmAdmin";String password = "admin";OKMWebservice ws = OKMWebservicesFactory.newInstance(host);
try{ws.login(user, password);// Get all latest workflow definitions foreach (ProcessDefinition pd in ws.workflow.findLatestProcessDefinitions()){System.Console.WriteLine("WF definition: " + pd); }}catch (Exception e){System.Console.WriteLine(e.ToString());}}}}findLastProcessDefinition
Section titled “findLastProcessDefinition”Description:
| Method | Return values | Description |
|---|---|---|
| findLastProcessDefinition(String name) | ProcessDefinition | Retrieves the last workflow definition of some specific workflow. |
The parameter name identifies a specific workflow definitions group.
Example:
using System;using System.Collections.Generic;using System.Linq;using System.Text;using com.openkm.sdk4csharp;using com.openkm.sdk4csharp.bean;
namespace OKMRest{public class Program{static void Main(string[] args){String host = "http://localhost:8080/openkm";String username = "okmAdmin";String password = "admin";OKMWebservice ws = OKMWebservicesFactory.newInstance(host);
try{ws.login(user, password);ProcessDefinition pd = ws.workflow.findLastProcessDefinition("purchase");System.Console.WriteLine("WF definition: " + pd);}catch (Exception e){System.Console.WriteLine(e.ToString());}}}}getProcessInstance
Section titled “getProcessInstance”Description:
| Method | Return values | Description |
|---|---|---|
| getProcessInstance(long piId) | ProcessInstance | Returns the process instance. |
The parameter piId is a valid process instance id.
Example:
using System;using System.Collections.Generic;using System.Linq;using System.Text;using com.openkm.sdk4csharp;using com.openkm.sdk4csharp.bean;
namespace OKMRest{public class Program{static void Main(string[] args){String host = "http://localhost:8080/openkm";String username = "okmAdmin";String password = "admin";OKMWebservice ws = OKMWebservicesFactory.newInstance(host);
try{ws.login(user, password);long piId = 5868; // Some valid process instance id ProcessInstance pi = ws.workflow.getProcessInstance(piId);System.Console.WriteLine("PI: " + pi);}catch (Exception e){System.Console.WriteLine(e.ToString());}}}}findUserTaskInstances
Section titled “findUserTaskInstances”Description:
| Method | Return values | Description |
|---|---|---|
| findUserTaskInstances() | TaskInstanceResultSet | Return a TaskInstanceResultSet object. |
Example:
using System;using System.Collections.Generic;using System.Linq;using System.Text;using com.openkm.sdk4csharp;using com.openkm.sdk4csharp.bean;
namespace OKMRest{public class Program{static void Main(string[] args){String host = "http://localhost:8080/openkm";String username = "okmAdmin";String password = "admin";OKMWebservice ws = OKMWebservicesFactory.newInstance(host);
try{ws.login(user, password);// Get all user task intancesTaskInstanceResultSet tasks = ws.workflow.findUserTaskInstances();foreach (TaskInstance ti in tasks.results){System.Console.WriteLine(ti.toString());}}catch (Exception e){System.Console.WriteLine(e.ToString());}}}}findTaskInstances
Section titled “findTaskInstances”Description:
| Method | Return values | Description |
|---|---|---|
| findTaskInstances(long piId) | List |
Retrieves a list of task instances of some process instance id. |
The parameter piId is a valid process instance id.
Example:
using System;using System.Collections.Generic;using System.Linq;using System.Text;using com.openkm.sdk4csharp;using com.openkm.sdk4csharp.bean;
namespace OKMRest{public class Program{static void Main(string[] args){String host = "http://localhost:8080/openkm";String username = "okmAdmin";String password = "admin";OKMWebservice ws = OKMWebservicesFactory.newInstance(host);
try{ws.login(user, password);// Get all task instances of some process instancelong piId = 8108; // Some valid process instance idforeach (TaskInstance ti in ws.workflow.findTaskInstances(piId)){System.Console.WriteLine(ti);}}catch (Exception e){System.Console.WriteLine(e.ToString());}}}}setTaskInstanceValues
Section titled “setTaskInstanceValues”Description:
| Method | Return values | Description |
|---|---|---|
| setTaskInstanceValues(long tiId, String transName, List |
void | Retrieves a list of task intances of some process instance id. |
The parameter tiId is a valid task instance id.
The parameter transName is the chosen transaction.
The parameter values are form element values needed for starting the workflow ( not all workflow tasks need form values ).
Example:
using System;using System.Collections.Generic;using System.Linq;using System.Text;using com.openkm.sdk4csharp;using com.openkm.sdk4csharp.bean;using com.openkm.sdk4csharp.bean.form;
namespace OKMRest{public class Program{static void Main(string[] args){String host = "http://localhost:8080/openkm";String username = "okmAdmin";String password = "admin";OKMWebservice ws = OKMWebservicesFactory.newInstance(host);
try{ws.login(user, password);long tiId = 8110; // Some valid task instance idList<FormElement> feList = new List<FormElement>();ws.workflow.setTaskInstanceValues(tiId, "approve", feList);}catch (Exception e){System.Console.WriteLine(e.ToString());}}}}getTaskInstance
Section titled “getTaskInstance”Description:
| Method | Return values | Description |
|---|---|---|
| getTaskInstance(long tiId) | TaskInstance | Returns a task instance. |
The parameter tiId is a valid task instance id.
Example:
using System;using System.Collections.Generic;using System.Linq;using System.Text;using com.openkm.sdk4csharp;using com.openkm.sdk4csharp.bean;
namespace OKMRest{public class Program{static void Main(string[] args){String host = "http://localhost:8080/openkm";String username = "okmAdmin";String password = "admin";OKMWebservice ws = OKMWebservicesFactory.newInstance(host);
try{ws.login(user, password);long tiId = 8110; // Some valid task instance idTaskInstance ti = ws.workflow.getTaskInstance(tiId);System.Console.WriteLine(ti);}catch (Exception e){System.Console.WriteLine(e.ToString());}}}}startTaskInstance
Section titled “startTaskInstance”Description:
| Method | Return values | Description |
|---|---|---|
| startTaskInstance(long tiId) | void | Starts a task instance. |
The parameter tiId is a valid task instance id.
Example:
using System;using System.Collections.Generic;using System.Linq;using System.Text;using com.openkm.sdk4csharp;
namespace OKMRest{public class Program{static void Main(string[] args){String host = "http://localhost:8080/openkm";String username = "okmAdmin";String password = "admin";OKMWebservice ws = OKMWebservicesFactory.newInstance(host);
try{ws.login(user, password);long tiId = 8110; // Some valid task instance idws.workflow.startTaskInstance(tiId);}catch (Exception e){System.Console.WriteLine(e.ToString());}}}}setTaskInstanceActorId
Section titled “setTaskInstanceActorId”Description:
| Method | Return values | Description |
|---|---|---|
| setTaskInstanceActorId(long tiId, String actorId) | void | Starts a task instance. |
The parameter tiId is a valid task instance id.
The parameter actorId must be a valid OpenKM userId.
Example:
using System;using System.Collections.Generic;using System.Linq;using System.Text;using com.openkm.sdk4csharp;
namespace OKMRest{public class Program{static void Main(string[] args){String host = "http://localhost:8080/openkm";String username = "okmAdmin";String password = "admin";OKMWebservice ws = OKMWebservicesFactory.newInstance(host);
try{ws.login(user, password);long tiId = 8110; // Some valid task instance idws.workflow.setTaskInstanceActorId(tiId, "okmAdmin");}catch (Exception e){System.Console.WriteLine(e.ToString());}}}}endTaskInstance
Section titled “endTaskInstance”Description:
| Method | Return values | Description |
|---|---|---|
| endTaskInstance(long tiId, String transName) | void | Starts a task instance. |
The parameter tiId is a valid task instance id.
The parameter transName is a transaction name.
Example:
using System;using System.Collections.Generic;using System.Linq;using System.Text;using com.openkm.sdk4csharp;
namespace OKMRest{public class Program{static void Main(string[] args){String host = "http://localhost:8080/openkm";String username = "okmAdmin";String password = "admin";OKMWebservice ws = OKMWebservicesFactory.newInstance(host);
try{ws.login(user, password);long tiId = 8110; // Some valid task instance idws.workflow.endTaskInstance(tiId, "end");}catch (Exception e){System.Console.WriteLine(e.ToString());}}}}getProcessDefinitionForms
Section titled “getProcessDefinitionForms”Description:
| Method | Return values | Description |
|---|---|---|
| getProcessDefinitionForms(long pdId) | Dictionary<String, List |
Return a map with all the process definition forms. |
The parameter pdId value is a valid workflow process definition.
Example:
using System;using System.Collections.Generic;using System.Linq;using System.Text;using com.openkm.sdk4csharp;using com.openkm.sdk4csharp.bean.form;
namespace OKMRest{public class Program{static void Main(string[] args){String host = "http://localhost:8080/openkm";String username = "okmAdmin";String password = "admin";OKMWebservice ws = OKMWebservicesFactory.newInstance(host);
try{ws.login(user, password);Dictionary<String, List<FormElement>> forms = ws.workflow.getProcessDefinitionForms(1);foreach (KeyValuePair<String, List<FormElement>> pair in forms){System.Console.WriteLine("Key:"+ pair.Key);foreach (FormElement fe in pair.Value){System.Console.WriteLine("Fe:"+ fe);}}}catch (Exception e){System.Console.WriteLine(e.ToString());}}}}getProcessDefinitionImage
Section titled “getProcessDefinitionImage”Description:
| Method | Return values | Description |
|---|---|---|
| getProcessDefinitionImage(string pdId, string uuid) | string | Returns an image as a string. |
The parameter pdId value is a valid workflow process definition.
Example:
using System;using System.Collections.Generic;using System.Linq;using System.Text;using com.openkm.sdk4csharp;using com.openkm.sdk4csharp.bean.form;
namespace OKMRest{public class Program{static void Main(string[] args){String host = "http://localhost:8080/openkm";String username = "okmAdmin";String password = "admin";OKMWebservice ws = OKMWebservicesFactory.newInstance(host);
try{ws.login(user, password);string tiId = "1";string res = ws.workflow.getProcessDefinitionImage(tiId, "a978f8e6-aa87-4f0f-b7bc-6f44cb090fdf");System.Console.WriteLine(res);}catch (Exception e){System.Console.WriteLine(e.ToString());}}}}findPooledTaskInstances
Section titled “findPooledTaskInstances”Description:
| Method | Return values | Description |
|---|---|---|
| findPooledTaskInstances() | TaskInstanceResultSet | Return a TaskInstanceResultSet object. |
Example:
using System;using System.Collections.Generic;using System.Linq;using System.Text;using com.openkm.sdk4csharp;using com.openkm.sdk4csharp.bean;
namespace OKMRest{public class Program{static void Main(string[] args){String host = "http://localhost:8080/openkm";String username = "okmAdmin";String password = "admin";OKMWebservice ws = OKMWebservicesFactory.newInstance(host);
try{ws.login(user, password);TaskInstanceResultSet tasks = ws.workflow.findPooledTaskInstances();foreach (TaskInstance ti in tasks.results){System.Console.WriteLine(ti.toString());}}catch (Exception e){System.Console.WriteLine(e.ToString());}}}}findProcessInstancesByNode
Section titled “findProcessInstancesByNode”Description:
| Method | Return values | Description |
|---|---|---|
| findProcessInstancesByNode(String uuid) | List |
Retrieves a list of all process instances by node of some registered workflows definition. |
The parameter uuid can be any document, mail, folder or record UUID.
Example:
using System;using System.Collections.Generic;using System.Linq;using System.Text;using com.openkm.sdk4csharp;using com.openkm.sdk4csharp.bean;
namespace OKMRest{public class Program{static void Main(string[] args){String host = "http://localhost:8080/openkm";String username = "okmAdmin";String password = "admin";OKMWebservice ws = OKMWebservicesFactory.newInstance(host);
try{ws.login(user, password);string uuid = "926ee2b3-44d8-4f8a-8b0a-864a0d829971";foreach (ProcessInstance pi in ws.workflow.findProcessInstancesByNode(uuid)){System.Console.WriteLine("PI: " + pi.toString());}}catch (Exception e){System.Console.WriteLine(e.ToString());}}}}getSuggestBoxKeyValue
Section titled “getSuggestBoxKeyValue”Description:
| Method | Return values | Description |
|---|---|---|
| getSuggestBoxKeyValue(long pdId, String uuid, String taskName, String propertyName, String key) | String | Returns the suggestBox value for a key. |
Example:
using System;using System.Collections.Generic;using System.Linq;using System.Text;using com.openkm.sdk4csharp;using com.openkm.sdk4csharp.bean;
namespace OKMRest{public class Program{static void Main(string[] args){String host = "http://localhost:8080/openkm";String username = "okmAdmin";String password = "admin";OKMWebservice ws = OKMWebservicesFactory.newInstance(host);
try{ws.login(user, password);long pdId = 2;String taskName = "task-elaboration";Console.WriteLine(ws.workflow.getSuggestBoxKeyValue(pdId, "9c069bdc-4654-4066-b4b2-d203b23e58fa", taskName, "suggestbox", "es"));}catch (Exception e){System.Console.WriteLine(e.ToString());}}}}getSuggestBoxKeyValuesFiltered
Section titled “getSuggestBoxKeyValuesFiltered”Description:
| Method | Return values | Description |
|---|---|---|
| getSuggestBoxKeyValuesFiltered(long pdId, String uuid, String taskName, String propertyName, String filter) | Dictionary<String, String> | Retrieves a map - (key, value) pairs - with suggestBox values |
Example:
using System;using System.Collections.Generic;using System.Linq;using System.Text;using com.openkm.sdk4csharp;using com.openkm.sdk4csharp.bean;
namespace OKMRest{public class Program{static void Main(string[] args){String host = "http://localhost:8080/openkm";String username = "okmAdmin";String password = "admin";OKMWebservice ws = OKMWebservicesFactory.newInstance(host);
try{ws.login(user, password);long pdId = 2;Dictionary<String, String> values = ws.workflow.getSuggestBoxKeyValuesFiltered(pdId, "9c069bdc-4654-4066-b4b2-d203b23e58fa", "task-elaboration", "suggestbox", "pai");foreach (KeyValuePair<string, string> value in values){Console.WriteLine(value.Key + ":" + value.Value);}}catch (Exception e){System.Console.WriteLine(e.ToString());}}}}