This is an example of how we can work with Content Manager Manage-In-Place Origins using a customer Workbook activity in the File Analysis Suite.
Content Manager 10.1 introduced a new feature to manage in-place documents in a file share. This feature leaves the file where it resides on the source file share, but creates a record object in Content Manager. Content Manager can then preview the document which calls back to the source document at the file share, but can also manage the retention and disposition of the file object. When Content Manager disposes (deletes/archives) the record, it will remove the document from the source file share as well.
The PowerShell example Is provided below:
# Manage-In-Place File System documents with Content Manager
# 02/10/2023 - Patrick Johnson
# ***Custom workbook activity to manage-in-place file system documents using the CM10.1 File System MiP feature***
# 1) Checks for a FAS custom activity called "cm-mip"
# 2) Checks if the file is from a file share repository, otherwise skips the file
# 3) Retrieves the file full path and name
# 4) Calls the origin object for CM
# 5) Adds the files of the workbook to the origin object
# 6) Applies a custom tag in FAS on the item to indicate it has been managed-in-place. Tag called "Managed-In-Place CM Record"
# NOTE: You must have access to the file share repository where the files are located when running this script
#Name of Manage-In-Place Origin to use during import
$mipName = "FAS MiP Origin"
#Name of FAS tag that will be applied to documents that successfully get managed-in-place
$tagName = "CM Managed In-Place"
#----------Connect to Content Manager Dataset
#Load CM SDK and Connect to DB
Add-Type -Path "C:\Program Files\Micro Focus\Content Manager\TRIM.SDK.dll"
$database = New-Object TRIM.SDK.Database;
#Set your DBID to work in
$database.Id = "CO"
#Set your Workgroup Server to connect to
$database.WorkgroupServerName = "localhost"
$database.Connect()
$dbName = $database.Name
Write-Host -ForegroundColor Cyan "Connected to: " $dbName
#----------
#----------Authenticate to FAS tenant and retrieve access token
#Request FAS tenant password
$pass = Read-Host 'What is your password?'
#FAS Authentication details
$auth = @"
{"tenantId":"pjohnson",
"user":"fasapi@scm.net",
"password":"$pass"
}
"@
$headerA = @{
"Content-Type" = "application/json"
}
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
#Get token via post
$loginResponse = Invoke-RestMethod -Uri "https://www.demo.microfocusfileanalysis.com:9310/v1/auth/login" -Method 'Post' -Body $auth -Headers $headerA -UseBasicParsing
$token = $loginResponse.accessToken.ToString()
#Write-Output "Access token is $token"
#----------
#----------Lookup Tag ID for application to items in FAS that have succesfully been managed
$tagHeader = @{
"Accept" = "application/json"
"Authorization" = "Bearer $token"
"Content-Type" = "application/json"
}
#Look Up Tag in FAS
$tagAnswer = Invoke-RestMethod -Uri "https://www.demo.microfocusfileanalysis.com:9310/cc/v1/processing/tags?nameFilter=$tagName&limit=-1&offset=0" -Method 'Get' -Headers $tagHeader -UseBasicParsing
$tagID = $tagAnswer.Id.ToString()
Write-Output -ForegroundColor Cyan "Tag ID = " $tagID
Write-Output -ForegroundColor Cyan "Tag Name = " $tagAnswer.Name
#----------
#----------Find the custom workbook activities requiring processing in the "cm-mip" type
$params0 = @{
Uri = 'https://www.demo.microfocusfileanalysis.com:9310/ca/v1/workspace/custom-activity-workbooks/cm-mip?processingStatus=Pending'
Headers = @{ 'Authorization' = "Bearer $token" }
Method = 'GET'
ContentType = 'application/json' }
#Execute Rest call
$custActResponse = Invoke-RestMethod @params0 -UseBasicParsing
Write-Output -ForegroundColor Cyan "Found workbooks for external processing" $custActResponse.Count.ToString()
#----------
#----------Iterate through workbooks with custom activity of "cm-mip" and process items
foreach ($item in $custActResponse)
{
$workbookID = $item.Id.ToString()
$workspaceID = $item.workspaceId.ToString()
Write-Output -ForegroundColor Cyan "Processing Workbook $workbookID"
$header = @{
"Accept" = "application/json"
"Authorization" = "Bearer $token"
"Content-Type" = "application/json"
}
Write-Output -ForegroundColor Cyan "Call to set status to processing"
$status = @{
"status" = "Processing"
"successCount" = 0
"errorCount" = 0
} | ConvertTo-Json
#Call to set status of Workbook to processing
Invoke-RestMethod -Uri "https://www.demo.microfocusfileanalysis.com:9310/ca/v1/workspace/$workspaceID/workbook/$workbookID/custom-activity/cm-mip" -Method 'Put' -Body $status -Headers $header -UseBasicParsing
#Now get the list of files in the workbook
$searchResponse = Invoke-RestMethod -Uri "https://www.demo.microfocusfileanalysis.com:9310/ca/v1/workspace/$workspaceID/workbook/$workbookID/documents?queryFields=collection_status%2Cfile_ext&limit=1000" -Method 'Get' -Headers $header -UseBasicParsing
#Establish Origin object in CM and lookup origin by name
$mipOrigin = New-Object TRIM.SDK.Origin ($database,$mipName)
#Retrieve Manage-In-Place Origin from CM and check whether it's of type GenericMip, otherwise skip
Write-Host -ForegroundColor Cyan "Origin Type: " $mipOrigin.TypeOfOrigin.ToString()
if ($mipOrigin.TypeOfOrigin.ToString() -eq "GenericMip")
{
Write-Host -ForegroundColor Cyan "Origin is of type GenericMip - Processing ... "
#Returns an Origin history object for associating with any imported records in this batch
$oHistory = $mipOrigin.StartBatch($mipPath)
#Iterate through each item of the FAS workbook and retrieve document path+name and create record in CM using MipOrigin
foreach ($item in $searchResponse.documentMetadataList)
{
Write-Host -ForegroundColor Green "Processing: " $item.documentId.ToString()
Write-Host -ForegroundColor Green "File: " $item.metadata.filepath
#Establish File Object that will be managed-in-place for currently processing document of FAS workbook
[System.IO.FileInfo]$fileToProcess = $item.metadata.filepath
#Process document as record with Origin definition here
$record = New-Object TRIM.SDK.Record ($database)
$record = $mipOrigin.NewRecord($oHistory)
#Calling to trigger the origin functionality to create a new folder and allocate it to this record
$mipOrigin.AllocateContainer($record)
$record.Title = $fileToProcess.Name
$doc = New-Object TRIM.SDK.InputDocument
$doc.SetAsManageInPlaceItem($mipOrigin.ManageInPlaceStore,$fileToProcess.FullName,$fileToProcess.Length,$fileToProcess.Extension,$fileToProcess.LastWriteTime)
$record.SetDocument($doc,$true,$false,"Documentadded: $mipName")
$record.Save()
#----------Here we'll establish the tag on the document in FAS. The Tag was specified earlier and the ID was retrieved for use here
#Header for document to tag
$tagDocHeader = @{
"Accept" = "application/json"
"Authorization" = "Bearer $token"
"Content-Type" = "application/json"
}
#JSON payload detailing the tag ID to use and document to be tagged
$tagJSON = @"
{
"addItems": {
"entityIds": [
$($tagID)
],
"itemIds": [
$($item.documentId.ToString())
]
}
}
"@
#Tag Item
Invoke-RestMethod -Uri "https://www.demo.microfocusfileanalysis.com:9310/research/v1/document/tag" -Method 'Post' -Body $tagJSON -Headers $tagDocHeader
#----------
}
}
else
{
Write-Host -ForegroundColor Red "Origin is not of type GenericMip - Not Processing. "
}
#----------Disconnect from CM database
$database.Dispose()
Write-Host -ForegroundColor Cyan "Disconnected from: " $dbName
#----------
#----------Now we set the workbook status to completed
Write-Output -ForegroundColor Cyan "Call to set status to completed"
$status = @{
"status" = "Completed"
"successCount" = $searchResponse.documentMetadataList.Count
"errorCount" = 0
} | ConvertTo-Json
#Call to set status to completed
Invoke-RestMethod -Uri "https://www.demo.microfocusfileanalysis.com:9310/ca/v1/workspace/$workspaceID/workbook/$workbookID/custom-activity/cm-mip" -Method 'Put' -Body $status -Headers $header -UseBasicParsing
#----------
}