Start a SmartPost process using a script

You can start a SmartPost process by calling the Process service and posting arguments in JSON format. You can use the following parameters:

Name Description Example

Cred

Credentials of the WorkZone used to invoke the request. If is not supplied, the user is prompted for credentials.

 

WzUrl

The main URL to WorkZone.

http://db01

WzODataUrl

The sub URL to the OData site under WorkZone The default value is 'OData'.

'OData'

FileKey

The FileKey of the case to run the SmartPost from

932835

Title

The title of the SmartPost process started, This is the title shown in the Processes overview. If the title is not supplied, the title of the document is used.

 

DefinitionId

The unique ID (GUID) of the SmartPost process to use. The default value is '23b9498e-bca5-4746-98a0-71e03cd6963c'.  
Description

Optional argument. Used to supply a description for the SmartPost process.

 

Deadline

If a SmartPost message is sent for preview or approval, a deadline can be set. If the deadline for the preview or approval is exceeded, a reminder is sent to the previewer or approver. This argument defines the deadline. The default value is 'tomorrow'.

 

Subject

The subject is the title of the message that is handed over to the dispatcher. When sending to e-Boks, the subject is the title of the message shown to the end user. If the subject argument is not supplied the Title will be used.

 

RecordID

The RecordID of the document to send. The argument is mandatory.

 

AttachmentRecordIds

Contains the recordid's of the attachments. The attached documents must exist in the WorkZone database.

 

IsApproval

Switch parameter. This argument indicates that the dispatch will be forwarded to the case handler for approval. IsApproval and IsPreview are mutually exclusive so only one of them or none of them can be true.

 

IsDeleteOriginal

Switch parameter. If supplied, the original document is deleted after dispatch is done.

 

Ispreview

Switch parameter. This argument indicates that the messege is sent to the process owner for preview before the dispatch continues. IsPreview and IsApproval are mutually exclusive so only one of them or none of them can be true.

 

RecipientAddressKeys

Addresskeys of the recipients. At least one must be specified.

 

CopyRecipientAddressKeys

Addresskeys of the copy recipients.

 

DispatcherSequenceId

The ID of the dispatcher sequence used for dispathing the document. The argument is mandatory.

 

CloseCase

A switch parameter. If supplied, the case will be closed after dispatch.

 

OpenCase

A switch parameter. If supplied and the case is closed, it will be opened before starting the SmartPost process.

 

CaseState

The new state of the case, which is applied after the dispatch is done. If not supplied, the state of the case remains unchanged. It must be a legal value in Custom domain 'SAGTILST'.

 

Access

Sets an access restriction on the SmartPost process. It must be a legal AccessCode. If the argument is not supplied, the default access code configured for the process is used.

 

Importance Argument used to set the priority of the SmartPost process. The possible values are '1-HIGH', '2-NORMAL' and '3-LOW'. The Default value is '2-NORMAL'.  
CustomDispatcherParameters This parameter can be used for supplying dispatcher specific parameters as a Hashtable.  
MaterialId The e-Boks material ID to use for the dispatch. The parameter is only used when using an e-Boks dispatcher and in this case, the argument is mandatory.  
RemotePrintTypeId The PrintTypeID for the dispatch. The parameter is only used when using a remote print dispatcher and in this case, the argument is mandatory.  

AllowSendingSeparateDocuments

Allows sending attachments as separate PDF documents separately instead of merging the letter and attachments into one PDF document.

 

DefaultSendSeparateDocuments

Ensures that sending attachments as separate PDF documents (see AllowSendingSeparateDocuments) separately is used by default.

 

:MergeAllDocuments

The parameter only has effect if you have turned on the AllowSendingSeparateDocuments parameter. If turned on, the PDF version of the letter will also include attachments.

 

SendAttention

If dispatch failed a notification user task will be created.

 

TerminateOnFailedDispatch

If dispatch failed process will be terminated instead of completed.

 

AllowOfficeRemerge

If turned on, a document already merge in Office will be remerged before sending.

 

PdfFailIfOutOfBounds

If turned on, when document contents is out of bounds PDF conversion will fail.

 

ValidatePDFUA

If turned on, the letter and attached documents will be validated against the PDF/UA standards. Only PDF and Word documents are supported

 

Note: The script allows for future changes in the parameters. The script calls the process service, finds allowed parameters, and then merges the parameters that are input to the script with the allowed parameters. The script will work even if a new non-mandatory parameter is added to SmartPost.

Example

.\Send-SmartPost.ps1 -WzUrl http://xe -FileKey 221 -Title "Test title" -RecordId 240 -RecipientAddressKeys 301 -DispatcherSequenceId 70

Below is an sample PowerShell script:


		<#
  .DESCRIPTION

    The 'Send-Smartpost' method is able to initiate a Smartpost shipment given the internal keys for case, record etc.
    An example of a start of a local print shipment. If credentials are not supplied in the parameter 'Cred', then a login dialog will be shown.

    .\Send-SmartPost.ps1 -FileKey 221 -Title "Test title" -RecordId 240  -RecipientAddressKeys 301 -DispatcherSequenceId 70  -WzUrl http://db01 -RemotePrintTypeId 1 -MaterialId 1 
    Ships a document and attchements to one or more recipients by initiating a SmartPost process.

  .SYNOPSIS
    This method calls the Process web service and initiates a SmartPost Workflow using the arguments supplied.

  .EXAMPLE
    PS C:\wzp\Source\Scanjour.Process.Web> Send-SmartPost -WzUrl http://db01 -FileKey 221 -Title "Test title" -RecordId 240  -RecipientAddressKeys 301 -DispatcherSequenceId 70

  .PARAMETER Cred
    Credentials of the workzone user used to invoke the request. If not supplied user is prompted for credentials.
   
  .PARAMETER WzUrl
    The main url to Workzone (e.g. http://db01)

  .PARAMETER WzODataUrl
    The sub url to the OData site under workzone  (e.g. 'OData'). The default value is 'OData'.
   
  .PARAMETER FileKey
   The FileKey of the file to run the SmartPost from (e.g. 932835)

  .PARAMETER Title
    The title of the SmartPost process started (the title presented in the process overview). If not supplied the title of the document.

  .PARAMETER DefinitionId
    The unique id (GUID) of the SmartPost process to use. Default value is '23b9498e-bca5-4746-98a0-71e03cd6963c'.

  .PARAMETER Description
    Optional argument. Used to supply a Description for the SmartPost process.

  .PARAMETER Deadline
    If a shipment is sent for preview or approval, a deadline can be set. If the deadline for the preview or approval is exceeded, a reminder is sent to the previewer or approver. This argument defines the deadline. The default value is 'tomorrow'. 

  .PARAMETER Subject
    The subject is the title of the message that is handed over to the dispatcher. When shipping to e-Boks the Subject is the title of the message presented to the enduser. If the subect argument is not supplied the Title will be used.

  .PARAMETER RecordID
    The RecordID of the document to ship. The argument is mandatory. 

  .PARAMETER AttachmentRecordIds
    Contains the recordid's of the attachements. The attchement documents must exist in the Workzone database.

  .PARAMETER IsApproval
    Switch parameter. This argument indicates that the shipment will be forwarded to the case handler for approval. IsApproval and IsPreview are mutually exclusive so only one of them or none of them can be true.

  .PARAMETER IsDeleteOriginal
    switch parameter. If supplied then the original document is deleted after shipment is done.

  .PARAMETER Ispreview
    Switch parameter. This argument indicates that the shipment is sent to the process initiator for preview before the shipment continues. IsPreview and IsApproval are mutually exclusive so only one of them or none of them can be true

  .PARAMETER RecipientAddressKeys
   Addresskeys of the recipients. At least one must be specified.

  .PARAMETER CopyRecipientAddressKeys
    Addresskeys of the copy recipients.

  .PARAMETER DispatcherSequenceId
    The ID of the Dispatcher sequence used for shipping the document. The argument is mandatory.

  .PARAMETER CloseCase
    A switch parameter. If supplied the case will be closed after shipment.

  .PARAMETER OpenCase
    A switch parameter. If supplied and the case is closed, it will be opened before starting the SmartPost process.

  .PARAMETER CaseState
    The new state of the case applied after the shipment is done. If not supplied the state of the case remains unchanged. Must be a legal value in Custom domain 'SAGTILST'.

	.PARAMETER Access
    Sets an access restriction on the SmartPost process. Must be a legal AccessCode. If the argument is not supplied the default access code configured for the process is used. 

  .PARAMETER Importance
    Argument used to set the priority of the SmartPost process. The possible values are '1-HIGH', '2-NORMAL' and '3-LOW'. The Default value is '2-NORMAL'.

  .PARAMETER CustomDispatcherParameters
    This parameter can be used for supplying dispatcher specific parameters as a Hashtable. 

  .PARAMETER MaterialId
    The e-Boks materialId to use for the shipment. The parameter is only used when using an e-Boks dispatcher is used and in this case the argument is mandatory.

  .PARAMETER RemotePrintTypeId
    The PrintTypeID for the shipment. The parameter is only used when using a remote print dispatcher is used and in this case the argument is mandatory.

  .PARAMETER AllowSendingSeparateDocuments
    Switch parameter. Sending documents separately over merging them into one is allowed

  .PARAMETER DefaultSendSeparateDocuments
    Switch parameter. Sending documents separately over merging them into one is selected
#>

param(
  [PSCredential]$Cred = (Get-Credential -Message "Workzone user login"),
  [parameter(Mandatory = $True)][string]$WzUrl,
  [parameter(Mandatory = $True)][string]$FileKey,
  [parameter(Mandatory = $True)][string]$Title,
  [string]$DefinitionId = "23b9498e-bca5-4746-98a0-71e03cd6963c",
  [string]$Description = $Title,
  [DateTime]$Deadline = [DateTime]::Now.AddDays(1),
  [string]$Subject = $Title,
  [parameter(Mandatory = $True)][string]$RecordId,
  [string[]]$AttachmentRecordIds = @(),
  [switch]$IsApproval,
  [switch]$IsDeleteOriginal,
  [switch]$Ispreview,
  [string[]]$RecipientAddressKeys,
  [string[]]$CopyRecipientAddressKeys,
  [string]$DispatcherSequenceId,
  [switch]$CloseCase,
  [switch]$OpenCase,
  [string]$CaseState,
  [string]$Access,
  [string]$Importance = "2-NORMAL",
  [HashTable]$CustomDispatcherParameters = @{},
  [string]$MaterialId,
  [string]$RemotePrintTypeId,
  [switch]$AllowSendingSeparateDocuments,
  [switch]$DefaultSendSeparateDocuments
)

Function ConvertTo-HashTable {
  param($Object)
  if ($null -eq $Object) { return $null }
   
  if ($Object -is [psobject] ) {
    $result = @{}
    $items = $Object | Get-Member -MemberType NoteProperty
    foreach ( $item in $items ) {
      $key = $item.Name
      $value = ConvertTo-HashTable -Object $object.$key
      $result.Add($key, $value)
    }
    return $result
  }
  elseif ($object -is [array]) {
    $result = [object[]]::new($object.Count)
    for ($i = 0; $i -lt $object.Count; $i++) {
      $result[$i] = (ConvertTo-HashTable -Object $object[$i])
    }
    return , $result
  }
  else {
    return $object
  }
}
   
Function Get-DefaultArguments {
  param(
    [PSCredential]$Cred,
    [string]$WzUrl = (Get-ModuleVar -Name "WzUrl"),   
    [parameter(Mandatory = $True)][string]$DefinitionId
  )
  [string]$Uri = "$($WzUrl)/Process/Process.svc/Definitions($($DefinitionId))/StartupInfo"
  $Arguments = Invoke-RestMethod -Uri $Uri -Credential $Cred
  ConvertTo-HashTable $Arguments
}
Function Start-WzpProcess {
  param(
    [PSCredential]$Cred,
    [string]$WzUrl = (Get-ModuleVar -Name "WzUrl"),
    [string]$EntityType = "File",
    [DateTime]$Deadline = ([DateTime]::Now.AddDays(1)),
    [parameter(Mandatory = $True)][string]$EntityId,
    [parameter(Mandatory = $True)][string]$DefinitionId,
    [parameter(Mandatory = $True)][string]$Title,
    [string]$Description,
    [parameter(Mandatory = $True)][HashTable]$Properties,
    [string]$Acces,
    [string]$Importance,
    [string]$ParentId,
    [string]$Owner,
    [string]$Subject
  )
   
  $UniqParam = "1$([System.Random]::new([Datetime]::Now.Millisecond).next(100000000,999999999))"   
  [string]$Uri = "$($WzUrl)/Process/Process.svc/Processes/${EntityType}/${EntityId}?uniqparam=${UniqParam}"
     
  $BodyHashTable = Get-DefaultArguments -Cred $Cred -WzUrl $WzUrl -DefinitionId $DefinitionId
  If (![string]::IsNullOrWhiteSpace($Title)) {
    $BodyHashTable["Title"] = $Title
  }
  If (![string]::IsNullOrWhiteSpace($Description)) {
    $BodyHashTable["Description"] = $Description
  }
  $BodyHashTable["Access"] = $Deadline
  If (![string]::IsNullOrWhiteSpace($Access)) {
    $BodyHashTable["Access"] = $Access
  }
  If (![string]::IsNullOrWhiteSpace($Importance)) {
    $BodyHashTable["Importance"] = $Importance
  }
  If (![string]::IsNullOrWhiteSpace($ParentId)) {
    $BodyHashTable["ParentId"] = $ParentId
  }
  If (![string]::IsNullOrWhiteSpace($Owner)) {
    $BodyHashTable["Owner"] = $Owner
  }
  If (![string]::IsNullOrWhiteSpace($Subject)) {
    $BodyHashTable["Subject"] = $Subject
  }
  foreach ($PropertyKey in $Properties.Keys) {
    if ($null -ne $BodyHashTable["Properties"][$PropertyKey] -and $null -ne $Properties[$PropertyKey]) {
      $BodyHashTable["Properties"][$PropertyKey].Value = $Properties[$PropertyKey]
    }
  }
   
  $Body = $BodyHashTable | ConvertTo-Json -Depth 10

  $Result = Invoke-WebRequest -Uri $Uri -Body $Body -Method Post -Credential $Cred
  return $Result.Content
}
   
 
if (![string]::IsNullOrWhiteSpace($MaterialId)) { $CustomDispatcherParameters.MaterialId = $MaterialId }
if (![string]::IsNullOrWhiteSpace($MaterialId)) { $CustomDispatcherParameters.RemotePrintTypeId = $RemotePrintTypeId }

$Properties = @{
  Subject                       = $Subject;
  RecordId                      = $RecordId;
  AttachmentRecordIds           = $AttachmentRecordIds;
  IsApproval                    = $IsApproval.IsPresent;
  IsDeleteOriginal              = $IsDeleteOriginal.IsPresent;
  IsPreview                     = $IsPreview.IsPresent;
  Deadline                      = $Deadline;
  CustomDispatcherParameters    = $CustomDispatcherParameters;
  RecipientAddressKeys          = $RecipientAddressKeys;
  CopyRecipientAddressKeys      = $CopyRecipientAddressKeys;
  DispatcherSequenceId          = $DispatcherSequenceId;
  CloseCase                     = $CloseCase.IsPresent;
  CaseState                     = $CaseState;
  OpenCase                      = $OpenCase.IsPresent;
  AllowSendingSeparateDocuments = $AllowSendingSeparateDocuments.IsPresent;
  DefaultSendSeparateDocuments  = $DefaultSendSeparateDocuments.IsPresent;
}

Start-WzpProcess -EntityId $FileKey -DefinitionId $DefinitionId -Title $Title -Description $Description -Subject $Subject -Properties $Properties -Importance $Importance -Cred $cred -WzUrl $WzUrl -Acces $Access

				

The copy image is missing