Create File Watcher Initiated Workflow or Custom Workflow
- Last UpdatedJun 10, 2024
- 4 minute read
AVEVA Work Tasks allows users to create Custom event provider initiated workflows. To implement it, first a custom event provider should be created.
After successfully creating a Custom Event Provider, we will see the steps for how to create an option for FileWatcher initiated WorkFlow.
Step 1:
-
Place an image icon under [AVEVA Work Tasks Installed Path]\AVEVA\Work Tasks\Web\BPMUITemplates\Default\Repository\ListControl\images\icons-ribbon folder. This icon will be displayed in the ribbon bar for associating with custom event provider.
-
Add an entry in the [AVEVA Work Tasks Installed Path]\AVEVA\Work Tasks\Web\BPMUITemplates\Default\Repository\ListControl\WorkflowRibbonBar.ascx page as shown below.
The following code should be added to the location where other event based workflow icons are defined (like Forms initiated WF). Find out the exact location and add the below code with the other similar kind of TDs.
<td height="25" align="left">
<span><a href="javascript:ExecuteAction('_sys_newfilewatcherworkflow')" class="sectionitem">
<img alt="<%=GetLangSpecText("ec_rbn_wf_bamworkflow_alttext")%>" src="<%=templateThemeDirectory%>Repository/ListControl/images/icons-ribbon/custom.PNG"
width="23" height="23" align="absmiddle" border="0" />
<%=GetLangSpecText("Customworkflow") %>
</a></span>
</td>
The above code will display the icon for the custom initiated workflow and it is linked to a javascript function.
If you check the WorkFlow list now, we can see that a new icon has been added to the ribbon bar.
The functionality for the new icon will be implemented in the following steps.
-
Create a workflow form aspx page in [AVEVA Work Tasks Installed Path]\AVEVA\Work Tasks\Web\BPMUITemplates\Default\Plugins\FileWatcher\Workflow directory. That aspx name can be specified in the function coming up in the next step.
-
To add a List Definition execute the following code by creating a project which has reference to the Workflow.net.dll and has the following using statements.
-
using Skelta.Repository.List;
-
using Skelta.Repository.List.Action;
Given below is the complete code file to get the function executed. The function InsertFileWatcherWorkflow() adds the list definition. This function accepts repository name as its parameter.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Workflow.NET;
using Skelta;
using Skelta.Repository.List;
using Skelta.Repository.List.Action;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
//The function to add a new
InsertFileWatcherWorkflow("W4ELoadRepo");
}
public void InsertFileWatcherWorkflow(string RepositoryName)
{
ListDefinition objList = new ListDefinition(new Skelta.Core.ApplicationObject(RepositoryName), "Workflow");
ActionNewWorkflow newFileWatcherWorkflow = new ActionNewWorkflow();
newFileWatcherWorkflow.Id = "_sys_newfilewatcherworkflow";
newFileWatcherWorkflow.Name = "ecm_list_cm_newfilewatcherworkflow";
newFileWatcherWorkflow.ShowWhenSecurityAllowsRights = string.Empty;
newFileWatcherWorkflow.ValidOnlyForItemStatus = string.Empty;
//newFileWatcherWorkflow.ValidOnlyForItemTypes = "0";
newFileWatcherWorkflow.PagePath = "../../Plugins/FileWatcher/Workflow/NewWorkflowForm.aspx";
//newFileWatcherWorkflow.ItemType = 1;
newFileWatcherWorkflow.ItemType = 5;
newFileWatcherWorkflow.Title = "New FileWatcher Workflow";
newFileWatcherWorkflow.Type = ListActionType.Task;
newFileWatcherWorkflow.WindowType = ListUIActionWindowTypes.Popup;
newFileWatcherWorkflow.WindowPosition = ListUIActionWindowPosition.Center;
newFileWatcherWorkflow.WindowSize = ListUIActionWindowSize.ScreenPropotional;
newFileWatcherWorkflow.DisplayValidRightValues = "ActionCreateFileWatcherWorkflow<True>";
newFileWatcherWorkflow.ActionAllowValidRightValues = "ActionCreateFileWatcherWorkflow<True>";
newFileWatcherWorkflow.ApprovalRequiredValidRightValues = string.Empty;
newFileWatcherWorkflow.ApprovalRequiredWithPromptValidRightValues = string.Empty;
// myList.Add(newFileWatcherWorkflow);
objList.Operations.Actions.Add(newFileWatcherWorkflow);
objList.Save();
}
}
}
Execute the following code once.
-
-
Run the script given below. Make an entry in the SKESecurityRigths Table.
-- First you need to make an entry in the SKESecurityRigths Table
DECLARE @Id AS UNIQUEIDENTIFIER
DECLARE @RepositoryName AS VARCHAR(100)
DECLARE @ParentItemId AS UNIQUEIDENTIFIER
DECLARE @UserId AS UNIQUEIDENTIFIER
DECLARE @EmptyId AS UNIQUEIDENTIFIER
DECLARE @TableId AS UNIQUEIDENTIFIER
SET @RepositoryName = 'Dec10Repo' -- Specify the Required Repostiory Name
DECLARE @Count as INT
Select @Count = Count(Id) from SKESecurityRights where RightCode='ActionCreateFileWatcherWorkflow' and application=@RepositoryName
IF(@Count = 0)
BEGIN
SET @Id = newid()
SET @EmptyId = NULL
SELECT @ParentItemId=Id,@UserId=CreatedBy,@TableId=TableId FROM SKESecurityRights WHERE RightCode='WorkflowListRights' and Application=@RepositoryName
INSERT INTO [dbo].[SKESecurityRights]
([Id],[Application],[CreatedBy],[CreatedDateTime],[LastUpdatedDateTime],[Title],[Description],[WIP],[WIPItemId],[MainItemId]
,[ParentItemId],[RecordParentItemId],[TableId],[ItemRowIndex],[IsLatest],[Version],[VersionHistory],[Status],[LockedBy],[LockedOn]
,[ListID],[SecuritySettings],[ItemId],[ItemType],[SecurityItemId],[Owner],[ModifiedBy],[RightCode],[Scope],[IsApplicableToFollower]
,[ControlType],[ControlFollowerType],[TypeFlag],[FollowerTypeFlag],[AuditTrail],[IsDisabled],[WorkflowStatus],[IsStandardRight]
,[SecurityCustomizationId])
VALUES
(@Id,@RepositoryName,@UserId,getdate(),getdate()
,'Can Create FileWatcher Workflow',NULL,0,NULL,@Id,@ParentItemId,NULL,@TableId,0,1,NULL,'|',3,NULL,NULL,NULL,NULL
,@Id,1,@EmptyId,@UserId,@UserId
,'ActionCreateFileWatcherWorkflow','ListSpecificForListLevel',1,'AllowDisallow','AllowDisallow',1,1,NULL,0,'',1,@EmptyId)
-- Next making entry into the SKERightsListMapping table
Declare @RightId as uniqueidentifier
Declare @ListId as Uniqueidentifier
select @ListId = Id from SKEListDefinition WHERE Name='Workflow' and Application=@RepositoryName
SET @Id = newid()
SELECT @RightId = Id FROM SKESecurityRights
WHERE RightCode = 'ActionCreateFileWatcherWorkflow' AND Application=@RepositoryName
INSERT INTO [dbo].[SKERightsListMapping]
([Id], [RightId], [ListID], [Application])
VALUES
(@Id, @RightId, @ListId, @RepositoryName)
-- Next making entries in the SKESGRightsMapping table for different security groups
-- Getting Default Security group id's
Declare @Admin as UniqueIdentifier
Declare @Contributor as uniqueIdentifier
declare @Reader as uniqueidentifier
declare @LimitedAccess as uniqueidentifier
select @Admin = Id from SKESecurityGroup where Title='Administrator' and application=@RepositoryName
select @Contributor = Id from SKESecurityGroup where Title='Contributor' and application=@RepositoryName
select @Reader = Id from SKESecurityGroup where Title='Reader' and application=@RepositoryName
select @LimitedAccess = Id from SKESecurityGroup where Title='Limited Access' and application=@RepositoryName
SET @Id = newid()
INSERT INTO [dbo].[SKESGRightsMapping]
([Id],[SecurityGroupId],[RightId],[ListID],[ListItemId],[Value]
,[FollowerValue],[EffectiveSGCustomizationId],[Application])
VALUES
(@Id, @Admin, @RightId, @EmptyId, @EmptyId
,'true', 'true', @EmptyId, @RepositoryName)
SET @Id = newid()
INSERT INTO [dbo].[SKESGRightsMapping]
([Id],[SecurityGroupId],[RightId],[ListID],[ListItemId],[Value]
,[FollowerValue],[EffectiveSGCustomizationId],[Application])
VALUES
(@Id, @Contributor, @RightId, @EmptyId, @EmptyId
,'true', 'true', @EmptyId, @RepositoryName)
SET @Id = newid()
INSERT INTO [dbo].[SKESGRightsMapping]
([Id],[SecurityGroupId],[RightId],[ListID],[ListItemId],[Value]
,[FollowerValue],[EffectiveSGCustomizationId],[Application])
VALUES
(@Id, @Reader, @RightId, @EmptyId, @EmptyId
,'false', 'false', @EmptyId, @RepositoryName)
SET @Id = newid()
INSERT INTO [dbo].[SKESGRightsMapping]
([Id],[SecurityGroupId],[RightId],[ListID],[ListItemId],[Value]
,[FollowerValue],[EffectiveSGCustomizationId],[Application])
VALUES
(@Id, @LimitedAccess, @RightId, @EmptyId, @EmptyId
,'false', 'false', @EmptyId, @RepositoryName)
END
ELSE
BEGIN
PRINT ('Entries already existing for Can Create AX Workflow right in the repository')
END
After all the steps to create the custom event provider initiated workflow are completed, verify the functionality by clicking the custom icon in the top menu. This should pop-up a new window where we can create a workflow. As we have illustrated with the filewatcher example, our custom event provider is file watcher only.
Click Save & Continue which will lead to the Process Designer where we can design the workflow. Publish the newly created workflow and try generating the event (creating a .doc file in this case) that is set to trigger the workflow.