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.  

Example:  

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

Below is an sample PowerShell script:


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
   )

Function Start-WzpProcess
{
   param(
   [PSCredential]$Cred=(Get-ScriptCredential ),
   [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,
   [switch]$UseHttps
   )

   $UniqParam="1$([System.Random]::new([Datetime]::Now.Millisecond).next(100000000,999999999))"
     
   [string]$Uri = "$($WzUrl)/Process/Process.svc/Processes/${EntityType}/${EntityId}?uniqparam=${UniqParam}"
  
   $Body=@{
     DefinitionId=$DefinitionId;
     Title=$Title;
     Description=$Description;
     Deadline=$Deadline;
     Properties=$Properties;
     Access=$Acces;
     Importance=$Importance;
     ParentId=$ParentId;
     Owner=$Owner;
     Subject=$Subject} | 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=@{Name="Subject";Type="System.String";Value=$Subject};
     RecordId=@{Name="RecordId";Type="System.String";Value=$RecordId};
     AttachmentRecordIds=@{Name="AttachmentRecordIds";Type="System.String[]";Value=$AttachmentRecordIds};
     IsApproval=@{Name="IsApproval";Type="System.Boolean";Value=$IsApproval.ToString()};
     IsDeleteOriginal=@{Name="IsDeleteOriginal";Type="System.Boolean";Value=$IsDeleteOriginal.ToString()};
     IsPreview=@{Name="IsPreview";Type="System.Boolean";Value=$IsPreview.ToString()};
     Deadline=@{Name="Deadline";Type="System.DateTime";Value=$Deadline};
     CustomDispatcherParameters=@{Name="CustomDispatcherParameters";Type="System.Collections.Generic.Dictionary``2[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Object, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089";Value=$CustomDispatcherParameters};
     RecipientAddressKeys=@{Name="RecipientAddressKeys";Type="System.String[]";Value=$RecipientAddressKeys};
     CopyRecipientAddressKeys=@{Name="CopyRecipientAddressKeys";Type="System.String[]";Value=$CopyRecipientAddressKeys};
     DispatcherSequenceId=@{Name="DispatcherSequenceId";Type="System.String";Value=$DispatcherSequenceId};
     CloseCase=@{Name="CloseCase";Type="System.Boolean";Value=$CloseCase.ToString()};
     CaseState=@{Name="CaseState";Type="System.String";Value=$CaseState};
     OpenCase=@{Name="OpenCase";Type="System.Boolean";Value=$OpenCase.ToString()};
   }
   
   Start-WzpProcess -EntityId $FileKey -DefinitionId $DefinitionId -Title $Title -Description $Description -Subject $Subject -Properties $Properties -Importance $Importance -Cred $cred -WzUrl $WzUrl -Acces $Access