Extend Laserfiche Workflow Functionality with the Workflow SDK

4 min read
  • Information Technology
  • Process Automation

Contributed by: Carl Sykes, Software Engineer, Laserfiche

Laserfiche Workflow SDK comes standard with Laserfiche Workflow 8.3 (though you have to install it separately). Like the Laserfiche SDK, which allows you to retrieve or send information to the Laserfiche Server, the Workflow SDK allows you to retrieve or send information to the Workflow Server. You can use it to do everything that the Workflow Server can do, including:

  • Start/terminate workflows.
  • Get the status of specific workflows.
  • Build custom Workflow activities.

Here are three different C# projects that use the Workflow SDK to:

  1. Initiate a workflow for a particular entry directly from within the Laserfiche Client.
  2. Retrieve workflow status and terminate a workflow for a particular entry directly from within the Laserfiche Client.
  3. Trigger a workflow using data entered into a form outside of Laserfiche.

Note: Before using the code samples below, you may want to familiarize yourself with Workflow SDK basics in this whitepaper: Getting Started with the Workflow SDK (Visual C#). A Support Site account is required to access this white paper.

Example 1: Initiate a workflow for a particular entry directly from within the Laserfiche Client

Scenario: Your organization has scheduled a particular workflow to run every evening to process invoices from a particular folder in Laserfiche. Every once in a while, an invoice will need to be processed and approved right away. You can add a button to your Laserfiche Client that, when clicked, will enable you to select a particular workflow from a list, and initiate it directly.

Here is how this process works:

  • Select the document in Laserfiche that you would like to process with Workflow.
  • Click on the custom button in the toolbar to launch a form that lists all available workflows.
  • Select the workflow that you would like to run and click Start.
  • This workflow will then be initiated and the invoice processed.

Here is the code for generating a list of available workflows.

private void FillWorkflows()
{
WorkflowApplication application = new WorkflowApplication();
application.Registration = new WorkflowServerRegistration("localhost");
using (WorkflowConnection conn = application.Open())
{
foreach (PublishedWorkflow workflow in conn.Database.GetAllPublishedWorkflows())
{
ListViewItem item = new ListViewItem(workflow.Name);
this.listView1.Items.Add(item);
}
}
}

Here is the code for the Start button.

private void StartWorkflow(string workflowName, string ruleName, StartingEntry entry, Initiator initiator)
{
WorkflowApplication application = new WorkflowApplication();
application.Registration = new WorkflowServerRegistration("localhost");
using (WorkflowConnection conn = application.Open())
{
PublishedWorkflow workflow = conn.Database.GetPublishedWorkflow(workflowName);
workflow.StartWorkflow(ruleName, entry, initiator, null, null);
}
}

Example 2: Retrieve workflow status and terminate a workflow for a particular entry directly from within the Laserfiche Client

Scenario: You need to delete an invoice but you want to make sure it isn’t currently being used by a workflow. If you do notice that it is being used by a workflow, terminate that workflow instance before deleting the invoice. To do this, you can add a custom button to your Laserfiche Client which will display a list of all workflows currently processing this document and enable you to terminate each instance before deleting the invoice.

Here is how this process works:

  • Select the document in Laserfiche that you would like to delete.
  • Click on the custom button in the toolbar to launch a form that lists the status of all the workflows that are currently using this document.
  • Select each of the workflows that you would like to terminate and click on Terminate.
  • The workflows will then be terminated and you can delete the document.

Here is the code to list the workflows that are using the selected entry.

private void FindInstances(int entryId, WorkflowConnection conn)
{
SearchFilterOptions options = new SearchFilterOptions();
options.MinEntryId = entryId;
options.MaxEntryId = entryId;
IEnumerable results = conn.Database.Tracking.SearchWorkflowInstances(options);
foreach (SearchResult result in results)
{
string workflowName = result.WorkflowInstance.WorkflowName;
string username = result.WorkflowInstance.Initiator.Name;
string startTime = result.WorkflowInstance.StartTime.ToString();
string statusTime = result.WorkflowInstance.StatusChanged.ToString();
Guid wfIntanceId = result.WorkflowInstance.InstanceId;
WorkflowInstanceStatus status = result.WorkflowInstance.Status;
bool isWaiting = status != WorkflowInstanceStatus.Completed && status != WorkflowInstanceStatus.Terminated;
AddItemToList(workflowName, username, startTime, statusTime, isWaiting, wfInstanceId);
}
}

Here is the code for the Terminate button.

private void TerminateInstance(Guid workflowInstnaceId, WorkflowConnection conn)
{
WorkflowInstance instance = conn.Database.Tracking.RetrieveWorkflowInstance(workflowInstanceId);
if (instance != null)
{
instance.Terminate();
}
}

Example 3: Trigger a workflow using data entered into a form outside of Laserfiche

Scenario: Every time a new employee is hired at your organization, the human resources department needs to e-mail that employee forms to fill out. Once the new employee fills out these forms, they need to be stored in the employee’s folder in Laserfiche. To streamline this process, HR staff can fill out a simple form and click a button to initiate a workflow that will create a new folder in the repository for the new hire and e-mail that person the required forms.

Here is how this process works:

  • Create a shortcut on your desktop to the New Employee application.
  • Double-click on the shortcut to launch a form.
  • After filling out the First Name, Last Name and Email fields, click on Add Employee.
  • This initiates a workflow that will create a new folder in the repository for the new hire and e-mail him the required forms. The values that were entered in the fields are used as tokens in the workflow.

Here is the code for the Add Employee button.

private void AddNewEmployee(string firstName, string lastName, string email, WorkflowConnection conn)
{
Dictionary<string, string> parameters = new Dictionary<string, string>();
PublishedWorkflow newEmployeeWF = conn.Database.GetPublishedWorkflow("BPM 252 – New Employee");
parameters.Add("FirstName", firstName);
parameters.Add("LastName", lastname);
parameters.Add ("EmployeeEmail", email);
newEmployeeWF.StartWorkflow(parameters);
}

Watch a 2-Minute Demo

Discover how your organization can go paperless, manage digital content, automate day-to-day processes and more.

WATCH A DEMO

Take a Product Tour

Enable the teams closest to your business processes to evolve and transform how your organization gets things done.

PRODUCT TOUR

Related Blogs

Can Generative AI and Content Services Increase Productivity and Transform Processes? Here’s How We’re Thinking About It.
How Banking Institutions Can Use Automation to Enhance the Customer Experience
Embrace The Game Changer: Transform Wealth Management Operations with AI-Driven Process Automations
Hyperautomation Is The Future, But It Starts With This First Step
Don’t Miss Your Connection: Secrets to Connecting Data with iPaaS

Book a Personalized Laserfiche Consultation Today

Privacy(Required)
Email Consent