Workflow samples
Basics
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);
Once you are logged with the webservices the session is keep in the webservice Object. Then you can use the other API method
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
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
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 definition
ws.workflow.deleteProcessDefinition(pdId);
}
catch (Exception e)
{
System.Console.WriteLine(e.ToString());
}
}
}
}
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 definition
ProcessDefinition pd = ws.workflow.getProcessDefinition(pdId);
System.Console.WriteLine(pd);
}
catch (Exception e)
{
System.Console.WriteLine(e.ToString());
}
}
}
}
runProcessDefinition
Description:
Method | Return values | Description |
---|---|---|
runProcessDefinition(long pdId, String uuid, List<FormElement> values) |
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 id
List<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
Description:
Method | Return values | Description |
---|---|---|
findAllProcessDefinitions() |
List<ProcessDefinition> |
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
Description:
Method | Return values | Description |
---|---|---|
findProcessInstances(long pdId) |
List<ProcessInstance> |
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 definitions
foreach (ProcessDefinition pd in ws.findAllProcessDefinitions())
{
System.Console.WriteLine("WF definition: "+pd);
// Get all process of some workflow definition
foreach (ProcessInstance pi in ws.workflow.findProcessInstances(pd.id))
{
System.Console.WriteLine("PI: "+pi);
}
}
}
catch (Exception e)
{
System.Console.WriteLine(e.ToString());
}
}
}
}
findLatestProcessDefinitions
Description:
Method | Return values | Description |
---|---|---|
findLatestProcessDefinitions() |
List<ProcessDefinition> |
Retrieves a list of the last workflows definitions. |
Can be several versions of the same workflow registered. |
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
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. Several workflow definition versions can have the same name. |
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
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
Description:
Method | Return values | Description |
---|---|---|
findUserTaskInstances(int offset, int limit) |
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 intances
TaskInstanceResultSet tasks = ws.workflow.findUserTaskInstances(0, 5);
foreach (TaskInstance ti in tasks.results)
{
System.Console.WriteLine(ti.toString());
}
}
catch (Exception e)
{
System.Console.WriteLine(e.ToString());
}
}
}
}
findTaskInstances
Description:
Method | Return values | Description |
---|---|---|
findTaskInstances(long piId) |
List<TaskInstance> |
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 instance
long piId = 8108; // Some valid process instance id
foreach (TaskInstance ti in ws.workflow.findTaskInstances(piId))
{
System.Console.WriteLine(ti);
}
}
catch (Exception e)
{
System.Console.WriteLine(e.ToString());
}
}
}
}
setTaskInstanceValues
Description:
Method | Return values | Description |
---|---|---|
setTaskInstanceValues(long tiId, String transName, List<FormeElement> valuess) |
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 id
List<FormElement> feList = new List<FormElement>();
ws.workflow.setTaskInstanceValues(tiId, "approve", feList);
}
catch (Exception e)
{
System.Console.WriteLine(e.ToString());
}
}
}
}
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 id
TaskInstance ti = ws.workflow.getTaskInstance(tiId);
System.Console.WriteLine(ti);
}
catch (Exception e)
{
System.Console.WriteLine(e.ToString());
}
}
}
}
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 id
ws.workflow.startTaskInstance(tiId);
}
catch (Exception e)
{
System.Console.WriteLine(e.ToString());
}
}
}
}
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 id
ws.workflow.setTaskInstanceActorId(tiId, "okmAdmin");
}
catch (Exception e)
{
System.Console.WriteLine(e.ToString());
}
}
}
}
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 id
ws.workflow.endTaskInstance(tiId, "end");
}
catch (Exception e)
{
System.Console.WriteLine(e.ToString());
}
}
}
}
getProcessDefinitionForms
Description:
Method | Return values | Description |
---|---|---|
getProcessDefinitionForms(long pdId) |
Dictionary<String, List<FormElement>> |
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
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
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
Description:
Method | Return values | Description |
---|---|---|
findProcessInstancesByNode(String uuid) |
List<ProcessInstance> |
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
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
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());
}
}
}
}