Creating a Workflow Report and Placing into Default Container

Someone asked if you could use powershell to generate a workflow status report and save it into the workflow's default container..... yes you can!

Add-Type -Path "D:\Program Files\Hewlett Packard Enterprise\Content Manager\HP.HPTRIM.SDK.dll"
$iseProc = Get-Process -id $pid
$db = New-Object HP.HPTRIM.SDK.Database
$wfs = New-Object HP.HPTRIM.SDK.TrimMainObjectSearch -ArgumentList $db, Workflow
$wfs.SearchString = "all"
$report = New-Object HP.HPTRIM.SDK.Report -ArgumentList $db, "Workflow Report"
$docRt = New-Object HP.HPTRIM.SDK.RecordType -ArgumentList $db, "Document"
foreach ( $wf in $wfs ) 
{
    if ( ([HP.HPTRIM.SDK.Workflow]$wf).DefaultContainer -ne $null ) 
    { 
        $wfc = New-Obect HP.HPTRIM.SDK.TrimMainObjectSearch -ArgumentList $db, Workflow
        $wfc.SearchString = "uri:$(([HP.HPTRIM.SDK.Workflow]$wf).Uri)"
        $pdf = $report.PrintReportToPdf($wfc)
        $pdfRec = New-Object HP.HPTRIM.SDK.Record -ArgumentList $db, $docRt
        $pdfRec.TypedTitle = "Workflow Report"
        $pdfRec.SetDocument($pdf)
        $pdfRec.SetContainer(([HP.HPTRIM.SDK.Workflow]$wf).DefaultContainer)
        $pdfRec.Save()
        $pdfRec.Dispose()
    }
}
$db.Dispose()

Removing Record Contact Relationships

Background

Whilst helping a customer upgrade to the latest version of Content Manager, I saw something that I've been seeing more often.  They had numerous unknown locations associated as contacts to their email records.  That is common enough, but these were improperly parsed SMTP addresses.  

The administrator of that dataset was manually removing these locations from the dataset as they have no value.  However, Content Manager does not allow you to remove a location if there are contact relationships in existence.  The screen-shot below demonstrates the error message you'd receive if you tried to manually remove the location.

Error Message

Error Message

To work around this the administrator was selecting a location to use as a replacement.  The end result is a location in Content Manager which is a contact on thousands upon thousands of records.  It doesn't make much sense to me.

Solution

One possible solution is to create a new add-in which would allow the administrator to remove the contact relationships before deleting the location.  Other possible solutions include: location add-in to automatically removing all contact relationships pre-delete, record add-in to automatically remove all contact relationships post-save, event processor add-in to automatically remove the contact relationships post record registration, and a stand-alone console app to show/correct all locations with this issue.  To me it makes the most sense to create a location add-in which allows the administrator to manually remove these contact relationships.  If the solution works well, then crafting something to do it in an automated fashion would make sense as the next step. 

You can download the add-in here.

Solution in Action

When the administrator right-clicks on a location they'll see this:

When the administrator clicks the "Remove Contact Relationships" they'll either be prompted to confirm the removal of the record contact relationships, like so:

Confirm Removal

Confirm Removal

Or the administrator will be told there are no relationships to remove:

No contact relationships Dialog

No contact relationships Dialog

After the removal has completed the results are shown to the administrator:

Removal Results Dialog

Removal Results Dialog

The add-in also works if you tag multiple locations and then invoke the add-in:

Multiple locations tagged

Multiple locations tagged

The behavior is slightly different when working with tagged locations.  You won't be prompted to confirm the removal.  The record contact relationships will be removed and then a results dialog will indicate the total number removed, as shown below.

Results when removing from tagged locations

Results when removing from tagged locations

Installing the Add-in

Launch the installer and then click next on the welcome dialog:

Welcome dialog

Welcome dialog

Alternate the installation path, if necessary, to reflect the actual folder of your HPE Content Manager x64 installation.  The installer does not intelligently detect the actual install folder.  Click Next after confirming installation path.

Installation Path

Installation Path

Click Install when presented with the confirmation dialog:

Confirmation Dialog

Confirmation Dialog

Depending on your workstation configuration, you may be prompted by Windows to authorize the installation.  Click yes if prompted.  Once the installation is completed you'll be shown the completion dialog.  Click Finish on that to close the installer. 

Completion Dialog

Completion Dialog

If you open windows Explorer you should see one new file in the installation folder:

Windows Explorer View

Windows Explorer View

Configuring the add-in

Open HPE Content Manager and then click External Links from the Administration ribbon:

HPE Content Manager Administration Ribbon

HPE Content Manager Administration Ribbon

Click New Generic Add-in (.Net):

External Link Dialog

External Link Dialog

Update the new generic add-in dialog as shown in the image below and then click Ok

Add-in Properties

Add-in Properties

If the Add-in is installed correctly then the dialog will close and you'll see the add-in listed in the listbox on the external links dialog, as shown below.

Click Properties and then click the Used By tab:

Check both the unknown and person location types and then click Ok.

Used By tab of the external link

Used By tab of the external link