This activity will allow you to have your document's original file name injected into a field to be used as metadata.
NOTE: Running the below powershell will add a custom activity into your process designer under the category Custom Activities.
Save Original File Name in a Configurable Field
Import-Module 'C:\Program Files\KnowledgeLake\Core\Modules\Capture.Core'
$role = Get-Role -Name "Activity Processing"
$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','Insert which field you would like populated.';
$parameterList.Add($fieldName);
# Save Original Filename as Metadata
############################################
# This activity will take the original file name and populate it in a metadata field
if((Get-ActivityDefinition -Name "Save Original File Name") -eq $null) {
Add-ActivityDefinition -Name "Save Original File Name" -Category "Custom Activities" -ActivityType Action -ActivityScope Default -Version 1 -Active 1 -RoleId $role.Id -ParametersList $parameterList -ScriptBlock {
$Context.Batch | Get-Document | ForEach-Object {
$input = Get-DocumentFile -Document $_ -DocumentFileType Input;
$inputFilename = $input.FileName;
Set-DocumentMetadata -Document $_ -ClassKey 'Index' -Key $fieldNameInput -Value $inputFileName;
}
}
}
Step by Step
- Our parameter list will consist of 1 string value
- The $fieldName parameter's configured string will set a value called $fieldNameInput and will be configured in process designer.
- The script block will then get an object of the current batch using $Context.batch and iterate through each document in that batch using a ForEach-Object.
- On each document, the script will then grab the Input File file name and set it to a variable called $inputFileName
- Each document will then have the field configured in process designer populated with the value found for $inputFileName
Installation
For instructions on deploying an activity, refer to our Deploying Custom Activities Article.
Configuration
The first example in this article doesn't have configuration. The second script however can be used by doing the following:
- Drag Save Original File Name to the Process Designer Canvas
- A Property Panel should show up on the right hand side of your Process Designer
- Fill out Field Name with the field you would like to populate with the Original File Name
- Click Save
NOTE: Only files that come from upload or an Import job will have an original file associated with them.
Comments
0 comments
Please sign in to leave a comment.