Use Content Handler
- Last UpdatedJun 10, 2024
- 4 minute read
Content Handler is used to access application specific data inside a workflow. Content Handlers can be used at the repository level and also at the workflow level. Using this content variable we can access application values in the custom table.
We will see the steps to implement a content handler.
-
Create a table in the database with the following script.
USE [DBName]
GO
/****** Object: Table [dbo].[LeaveApplications] Script Date: 03/29/2010 20:03:58 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[LeaveApplications](
[LeaveApplicationID] [int] NOT NULL,
[UserID] [int] NULL,
[FromDate] [datetime] NULL,
[ToDate] [datetime] NULL,
[NoOfDays] [int] NULL,
[LeaveType] [int] NULL,
[Reason] [int] NULL,
[ApplicationDate] [int] NULL,
CONSTRAINT [PK_LeaveApplications] PRIMARY KEY CLUSTERED
(
[LeaveApplicationID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
Add few rows of data for the created table.
-
Steps to create Repository level content Handler
An entry in the SKAddInProviders table is required for the content handler. Execute the following query for the repository database.
There will be already an entry for Provider Name IContentHandler by default which we can update and use for our specific example. Updating the entry with condition, provider name = IcontentHandler is sufficient in this example. Change the database name, tablename and security settings as required in the below query.
update SKAddInProviders
set [Settings]='<content><datasource type="sql server">server=Localhost;database=TestRepo;Integrated Security=true</datasource><tables><table name="LeaveApplications"><fields><field name="LeaveApplicationID" type="int" canUpdate="false" identifier="true" contentName="leaveapplicationid"/><field name="UserID" type="int" canUpdate="false" contentName="userid" /><field name="FromDate" type="datetime" canUpdate="false" contentName="fromdate"/><field name="ToDate" type="datetime" canUpdate="false" contentName="todate"/><field name="NoOfDays" type="int" canUpdate="false" contentName="noofdays"/><field name="LeaveType" type="int" canUpdate="false" contentName="leavetype"/><field name="Reason" type="int" canUpdate="false" contentName="reason"/><field name="ApplicationDate" type="int" canUpdate="false" contentName="applicationdate"/></fields><filter><![CDATA[LeaveApplicationID=<%#Variable.LeaveApplicationId%>]]></filter></table></tables></content>',
IsGlobal='True'
where name='IContentHandler'
-
Steps to create Repository level content Handler when the user's database is a part of the Repository.
An entry in the SKAddInProviders table is required for the content handler. Execute the following query for the repository database.There will be already an entry for Provider Name IContentHandler by default which we can update and use for our specific example. Updating the entry with condition, provider name = IcontentHandler is sufficient in this example. Since the database is a part of the Repository, the user need not use the previous code sample, but use the sample given below. In this sample you can see that instead of the connection string, the UseRepositoryConnectionString="yes" code is used.
update SKAddInProviders
set [Settings]='<content UseRepositoryConnectionString="yes"><tables><table name="LeaveApplications"><fields><field name="LeaveApplicationID" type="int" canUpdate="false" identifier="true" contentName="leaveapplicationid"/><field name="UserID" type="int" canUpdate="false" contentName="userid" /><field name="FromDate" type="datetime" canUpdate="false" contentName="fromdate"/><field name="ToDate" type="datetime" canUpdate="false" contentName="todate"/><field name="NoOfDays" type="int" canUpdate="false" contentName="noofdays"/><field name="LeaveType" type="int" canUpdate="false" contentName="leavetype"/><field name="Reason" type="int" canUpdate="false" contentName="reason"/><field name="ApplicationDate" type="int" canUpdate="false" contentName="applicationdate"/></fields><filter><![CDATA[LeaveApplicationID=<%#Variable.LeaveApplicationId%>]]></filter></table></tables></content>',
IsGlobal='True'
where Name='IContentHandler'
The defined entry will be inserted in the SKAddInProviders table after the successful execution of the above query.
-
Isglobal property decides whether the content handler will be available for the whole repository or not. If set to true, the handler will be available for the whole repository. If the Content handler has to be made available only for a specific workflow, then set IsGlobal Property as False and make an entry in the SKAddInProviderSettings
-
Steps to create WorkFlow level content Handler
This step has to be done only if the content handler is for a specific workflow. Delete the 'settings' column entry from the Content Handler and make it "Null"
Set the IsGlobal property as false in SKAddInProviders.
Make the following entry in the SKAddInProviderSettings table. Change the reponame, workflow name and the AddInProviderID(Id of the AddInProvider in the SKAddInProviders table) from the below query as required.
insert into SKAddInProviderSettings (Application,Workflow,AddInProviderID,Settings,IsDefault)
values
('RepoName','WorkFlowName','a8edae68-420f-450d-8df2-6a5b31389207','<?xml version="1.0" encoding="utf-8" ?><content><datasource type="sql server">server=localhost;database=TestRepo;Integrated Security=true</datasource><tables><table name="LeaveApplications"><fields><field name="LeaveApplicationID" type="int" canUpdate="false" identifier="true" contentName="leaveapplicationid"/><field name="UserID" type="int" canUpdate="false" contentName="userid" /><field name="FromDate" type="datetime" canUpdate="false" contentName="fromdate"/><field name="ToDate" type="datetime" canUpdate="false" contentName="todate"/><field name="NoOfDays" type="int" canUpdate="false" contentName="noofdays"/><field name="LeaveType" type="int" canUpdate="false" contentName="leavetype"/><field name="Reason" type="int" canUpdate="false" contentName="reason"/><field name="ApplicationDate" type="int" canUpdate="false" contentName="applicationdate"/></fields><filter><![CDATA[LeaveApplicationID=<%#Variable.LeaveApplicationId%>]]></filter></table></tables></content>','True')
-
Create a new workflow in the repository with a variable as the same name as of the FillterCondition set above (LeaveApplicationID in this example).
The whole XML file which can be used to import the below WF is given here. Import and make the necessary changes. Create another content variable which takes value from the client object which is calling the workflow.
//test is used here as we are using the following code to execute the workflow.
objClient.Execute(provider + "::" + virtualUserId, "<test>" + 10001 + "</test>");
10001 is one of the LeaveApplicationId in the table.
Use an update variable to set the value of the content variable to the Variable created.
Create a new Approval Activity on the "updated" link of the update activity with subject field as the from date in the Content Variable.
Publish and run the workflow using Client Object.Execute method. Pass the LeaveApplicationId along with it as shown below
objClient.Execute(provider + "::" + virtualUserId, "<test>" + 10001 + "</test>");
-
Go to the Inbox and you should be able to find an Approval activity with "from date" of the leave application as subject.
The Content Handler has been successfully implemented for the default dll.