Datapolis Process System SDK
Creating Activity Tutorial
This walkthrough will guide you through creating a custom activity. The assumed functional requirement for an activity created in this walkthrough is to create list.
The input parameters of the activity will be as follows:
The following parameters are returned by the activity:
Prerequisites
Before creating a custom activity, be sure you have installed all of the necessary components and Visual Studio templates.
Prepare xml files
Define the parameters in markup. Open WBCreateListActivity.xml and insert definition of the activity parameters.
<
Activities
xmlns
=
"http://www.datapolis.com.pl/WorkBox/Activities.xsd"
>
Activity
Name
"WBCreateListActivity"
IsCallExternalActivity
"False"
NamespaceName
"clr-namespace:Datapolis.WorkBox.Sdk.Samples.Activities;Assembly=Datapolis.WorkBox.Sdk.Samples, Version=1.0.0.0, Culture=neutral, PublicKeyToken=0a68baededa28155"
Title
"$Resources:Datapolis.WorkBox.Sdk.Samples.Activities,WBCreateListActivity_ActivityTitle;"
Description
"$Resources:Datapolis.WorkBox.Sdk.Samples.Activities,WBCreateListActivity_ActivityDescription;"
Parameters
Parameter
"ParentWebUrl"
Required
"True"
Type
"String"
DataType
"OneLookup"
ParametersToEraseAfterChange
"ListTemplate"
AllowChildrenTypes
"Current SharePoint SiteCollection Site WebCollection Web"
SelectableTypes
"Web"
"$Resources:Datapolis.WorkBox.Sdk.Samples.Activities,WBCreateListActivity_ParentWebUrl_Title;"
"$Resources:Datapolis.WorkBox.Sdk.Samples.Activities,WBCreateListActivity_ParentWebUrl_Description;"
/>
"ListTitle"
"$Resources:Datapolis.WorkBox.Sdk.Samples.Activities,WBCreateListActivity_ListTitle_Title;"
"$Resources:Datapolis.WorkBox.Sdk.Samples.Activities,WBCreateListActivity_ListTitle_Description;"
"ListDescription"
StringLines
"4"
"$Resources:Datapolis.WorkBox.Sdk.Samples.Activities,WBCreateListActivity_ListDescription_Title;"
"$Resources:Datapolis.WorkBox.Sdk.Samples.Activities,WBCreateListActivity_ListDescription_Description;"
RootPath
"@ParentWebUrl/WebParameterCollection/ListTemplateCollection/"
"$Resources:Datapolis.WorkBox.Sdk.Samples.Activities,WBCreateListActivity_ListTemplate_Title;"
"$Resources:Datapolis.WorkBox.Sdk.Samples.Activities,WBCreateListActivity_ListTemplate_Description;"
"IsQuickLuanch"
Value
"Bool"
"$Resources:Datapolis.WorkBox.Sdk.Samples.Activities,WBCreateListActivity_IsQuickLuanch_Title;"
"$Resources:Datapolis.WorkBox.Sdk.Samples.Activities,WBCreateListActivity_IsQuickLuanch_Description;"
ValueOptions
ValueOption
"$Resources:Datapolis.WorkBox.Sdk.Samples.Activities,WBCreateListActivity_IsQuickLuanch_True;"
"$Resources:Datapolis.WorkBox.Sdk.Samples.Activities,WBCreateListActivity_IsQuickLuanch_False;"
</
"ErrorStatus"
Direction
"Output"
"$Resources:Datapolis.WorkBox.Sdk.Samples.Activities,WBCreateListActivity_ErrorStatus_Title;"
"$Resources:Datapolis.WorkBox.Sdk.Samples.Activities,WBCreateListActivity_ErrorStatus_Description;"
"ReturnListUrl"
"$Resources:Datapolis.WorkBox.Sdk.Samples.Activities,WBCreateListActivity_ReturnListUrl_Title;"
"$Resources:Datapolis.WorkBox.Sdk.Samples.Activities,WBCreateListActivity_ReturnListUrl_Description;"
Graph
></
Set the activity translation.
data
name
"WBCreateListActivity_ActivityDescription"
xml:space
"preserve"
value
>Add a new list or library to the selected web</
"WBCreateListActivity_ActivityTitle"
>Code Sample: Create List</
"WBCreateListActivity_ErrorStatus_Description"
>When a list is created successfully the error status returns 0 otherwise an error message is returned</
"WBCreateListActivity_ErrorStatus_Title"
>Error Status</
"WBCreateListActivity_IsQuickLuanch_Description"
>Specify whether a link to this document library appears in the Quick Launch.</
"WBCreateListActivity_IsQuickLuanch_False"
>No</
"WBCreateListActivity_IsQuickLuanch_Title"
>Navigation</
"WBCreateListActivity_IsQuickLuanch_True"
>Yes</
"WBCreateListActivity_ListDescription_Description"
>Type descriptive text that will help site visitors use this document library or list.</
"WBCreateListActivity_ListDescription_Title"
>Description</
"WBCreateListActivity_ListTemplate_Description"
>Type a template for example: Events</
"WBCreateListActivity_ListTemplate_Title"
>Template</
"WBCreateListActivity_ListTitle_Description"
>Type a new name as you want it to appear in headings and links throughout the site</
"WBCreateListActivity_ListTitle_Title"
>Name</
"WBCreateListActivity_ParentWebUrl_Description"
>Select a parent web</
"WBCreateListActivity_ParentWebUrl_Title"
>Parent Web</
"WBCreateListActivity_ReturnListUrl_Description"
>The list default view url. When the value is empty see Error Status</
"WBCreateListActivity_ReturnListUrl_Title"
>List Url</
Develop code
private
static
readonly
Type createListType =
typeof
(WBCreateListActivity);
public
DependencyProperty ParentWebUrlProperty = DependencyProperty.Register(
,
(
string
), createListType);
DependencyProperty ListTitleProperty = DependencyProperty.Register(
DependencyProperty ListDescriptionProperty = DependencyProperty.Register(
DependencyProperty ListTemplateProperty = DependencyProperty.Register(
DependencyProperty IsQuickLuanchProperty = DependencyProperty.Register(
bool
?), createListType);
DependencyProperty ErrorStatusProperty = DependencyProperty.Register(
DependencyProperty ReturnListUrlProperty = DependencyProperty.Register(
[ValidationOption(ValidationOption.Required)]
ParentWebUrl
{
get
return
)
base
.GetValue(ParentWebUrlProperty); }
set
.SetValue(ParentWebUrlProperty, value); }
}
ListTitle
.GetValue(ListTitleProperty); }
.SetValue(ListTitleProperty, value); }
[ValidationOption(ValidationOption.Optional)]
ListDescription
.GetValue(ListDescriptionProperty); }
.SetValue(ListDescriptionProperty, value); }
ListTemplate
.GetValue(ListTemplateProperty); }
.SetValue(ListTemplateProperty, value); }
IsQuickLuanch
? quickLaunch = (
?)
.GetValue(IsQuickLuanchProperty);
if
(quickLaunch !=
null
&& quickLaunch.HasValue)
quickLaunch.Value;
false
;
.SetValue(IsQuickLuanchProperty, value); }
ErrorStatus
.GetValue(ErrorStatusProperty); }
.SetValue(ErrorStatusProperty, value); }
ReturnListUrl
.GetValue(ReturnListUrlProperty); }
.SetValue(ReturnListUrlProperty, value); }
SPListTemplate.QuickLaunchOptions QuickLaunch
this
.IsQuickLuanch)
SPListTemplate.QuickLaunchOptions.On;
SPListTemplate.QuickLaunchOptions.Off;
Now, create function CreateList that is responsible for business logic of this activity
When a list is created successfully the absolute list URL is returned as the output ReturnListUrl parameter and the activity error status is set to 0.
void
CreateList()
SPSecurity.RunWithElevatedPrivileges(
delegate
using
(var site =
new
SPSite(
.ParentWebUrl))
(var parentWeb = site.OpenWeb())
.Logger.Medium(
"Parameters: ParentWebUrl: '{0}', ListTitle: '{1}', ListDescription: '{2}', ListTemplate: '{3}', IsQuickLuanch: '{4}'"
.ParentWebUrl,
.ListTitle,
.ListDescription,
.ListTemplate,
.IsQuickLuanch);
var spListTemplate = WBWebHelper.GetListTemplate(parentWeb,
.ListTemplate);
(spListTemplate ==
var msg =
.Format(
"The list that title should be: '{0}' cannot be created as the template list (InternalName: '{1}') has not be found, ParentWebUrl: '{2}'"
.ParentWebUrl);
.ErrorStatus = msg;
.ReturnListUrl = msg;
.Logger.Unexpected(msg);
var listId = parentWeb.Lists.Add(
.ListDescription, spListTemplate);
(listId == Guid.Empty)
"The list that title should be: '{0}' could not be created as the list Id is empty, ParentWebUrl: '{1}', ListTemplate: '{2}'"
else
var list = parentWeb.Lists[listId];
list.OnQuickLaunch =
.IsQuickLuanch;
list.Update();
.ReturnListUrl = parentWeb.Url + list.DefaultViewUrl;
.ErrorStatus =
"0"
"The list that title is: '{0}' has been created successfully, ReturnListUrl: '{1}', ErrorStatus: '{2}'"
.ReturnListUrl,
.ErrorStatus);
});
protected
override
ActivityExecutionStatus ExecuteBody(ActivityExecutionContext c)
.Logger.Verbose(
"Starting ExecuteBody function of the create list activity"
);
try
.CreateList();
catch
(Exception e)
.ErrorStatus = e.Message;
.ReturnListUrl =
.Empty;
.Logger.Unexpected(
"An error occured during creation a new list"
, e);
"Ending ExecuteBody function of the create list activity"
ActivityExecutionStatus.Closed;
Build the project
Modify web.config
Browse to the web.config file of web application where the activity will be used. By default it's in \\Inetpub\wwwroot\wss\VirtualDirectories\Port_Number
Open the the web.config file and find the section: <System.Workflow.ComponentModel.WorkflowCompiler><authorizedTypes><targetFx version="v4.0">
Insert the following node:
<authorizedType Assembly=
"Datapolis.WorkBox.Sdk.Samples, Version=1.0.0.0, Culture=neutral, PublicKeyToken=0a68baededa28155"
Namespace=
"Datapolis.WorkBox.Sdk.Samples.Activities"
TypeName=
"*"
Authorized=
Save and close web.config
Next Step
Optionally, after reading this walkthrough you can see the same activity code attached in SDK Samples in Download section.