There are a few things every activity will have in common when being put into PowerShell. You will need to import the modules you are using, if they aren't already and set a few pieces of required information for each activity:
- Import Module
- Parameter List
- Activity Name
- Activity Category
- Activity Type
- Activity Scope
- Version
- Active
- Role
- Script Block
For instructions on deploying an activity, refer to our Deploying Custom Activities Article.
We will go through these below, but it should look something like this to start with the above bold for reference:
Import-Module 'C:\Program Files\KnowledgeLake\Core\Modules\Capture.Core'
$role = Get-Role -Name 'Activity Processing'
if((Get-ActivityDefinition -Name "Activity Name") -eq $null) {
Add-ActivityDefinition -Name 'Activity Name' -Category "Custom Activities" -ActivityType Action -ActivityScope Default -Version 1 -Active 1 -RoleId $role.Id -ParameterList $parameterList -ScriptBlock {
Insert Script Here
}
}
Import Module
All scripts provided will usually import the Capture.Core module as this is where a significant portion of our PowerShell cmdlets come from. There are also other modules for Repository and other parts of the product if required. You can see this done on the above bolded line:
Import-Module 'C:\Program Files\KnowledgeLake\Core\Modules\Capture.Core'
Parameter List
NOTE: -ParameterList is neither required nor will it always be present. Not having a parameter list won't cause any harm. If you choose to use Parameters, your activity might look like the example below as opposed to above:
Import-Module 'C:\Program Files\KnowledgeLake\Core\Modules\Capture.Core'
$parameterList = New-Object System.Collections.Generic.List[Capture.Core.Data.Contracts.Configuration.ParameterBase];
$fieldName = New-Object Capture.Core.Data.Configuration.Parameters.StringParameter -ArgumentList '','$fieldNameInput','Field Name','Field Description';
$paramterList.Add($fieldName);
$role = Get-Role -Name 'Activity Processing'
if((Get-ActivityDefinition -Name "Activity Name") -eq $null) {
Add-ActivityDefinition -Name 'Activity Name' -Category "Custom Activities" -ActivityType Action -ActivityScope Default -Version 1 -Active 1 -RoleId $role.Id -ParameterList $parameterList -ScriptBlock {
Insert Script Here
}
}
Parameter Lists are lists of potential configuration that you can generate in Process Designer if you don't want to hard-code in a value for a variable. These are used when an activity needs to be used multiple times for configurations that may have 1 or 2 configuration differences.
For the sake of our examples, we will always use a string defined using :
Capture.Core.Data.Configuration.Parameters.StringParameter
Activity Name
In PowerShell, our activities are referred to as Activity Definitions and you will see 2 instances of this in the code above on lines 4 and 5.
if((Get-ActivityDefinition -Name "Activity Name") -eq $null) {
Add-ActivityDefinition -Name 'Activity Name'...
The line starting with if... is checking to ensure that an activity with that name does not already exist. The second line is going to add the activity with the name you fill out after -Name.
Activity Category
Our activities belong to categories in your toolbox inside of Process Designer. These will not effect anything besides where the activity will be found inside the designer.
The categories we have out of the box are :
- Assist Activities
- Barcoding Activities
- Batch Split Activities
- Conversion Activities
- Image Processing
- Indexing Activities
- Metadata Activities
- Pre-Processing Activities
- Routing Activities
- Upload Activities
- Wrap-Up Activities
You do not need to use these categories if you don't want to. For the sake of all examples in our Knowledge Base, we use a category called Custom Activities so we can easily find them in our toolbox.
This will be set after the -Category parameter in the above script snippet.
Activity Type
-ActivityType is a back-end category we use to define the UI in Process Designer. For our purposes, this should always be set to Action.
Activity Scope
The -ActivityScope parameter is a deprecated property that is still required for legacy systems and is still required to be set. Ensure this is always set to Default.
Version
When adding a new activity, we will always set the -Version number to 1. When potentially updating an activity later on, you will want to increment this to ensure any batches in flight using version 1 do not encounter errors.
Active
-Active is a boolean that denotes whether the activity is active in the toolbox within Process Designer. 1 is Active and 0 will be Inactive.
Role
If you notice in the above snippet, the -RoleId is filled out differently than other parameters. The Role itself is acquired in line 2 and applied using a variable. This will be true for all activities as we cannot just pass in a string for the name.
NOTE: In most circumstances, using our default Activity Processing role will be sufficient unless you want to be more granular with how often this activity is run and on how many threads.
Script Block
The script block is going to be the actual PowerShell this activity will run when a batch enters the step. This will be wrapped in curly braces and has a few considerations to keep in mind.
- $Context.batch is a thing you will see a lot in these examples. This is referring to the batch the activity is currently working as opposed to having to do a Get-Batch to get something specific.
- ForEach-Object will often be used to iterate through documents inside a batch and have script blocks run on documents independently from one another.
- Document and Batch Metadata will consist of 3 Class Keys which are basically categories of metadata :
- General - Any information we want to store with a batch
- Index - Information that is user facing and indexable in our Apps for documents
- System - Back End information we use for processing
- Ensure you document your activities for future reference. This can be done by using a # at the beginning of a line to comment out that line. All of our examples will have this for at least the title and description of each activity.
Comments
0 comments
Please sign in to leave a comment.