/n software Adapters for BizTalk

Questions / Feedback?

Script Property

The PowerShell script to execute.

Data Type

String

Default Value

""

Remarks

A set of PowerShell expressions to execute when a message is sent through the adapter. This can be the script itself, or the dot-source for an external script file.

Accessing the BizTalk message inside the script

The BizTalk message being sent is made available within the script through the $message variable. This is a wrapper object around the real BizTalk message that makes it easier to use from PowerShell. The $message object has the following properties and methods:

  • GetBody(): This method returns the BizTalk message body as a string.
  • GetBodyB(): This method returns the BizTalk message body as a byte array.
  • MessageID: This property can be used to get the unique ID assigned to this BizTalk Message.
  • BodyPartName: This property will return the name of the body part of the message.
  • GetProperty(): This method takes the name and namespace of a context property and returns its value.
  • ReadBodyPart(): This method will return a System.IO.Stream object associated with the message Body Part.
  • ReadPart(): This method takes the name of a specific part in the message and returns its data Stream.
  • GetPartNames(): This method will return a list of the names of all parts available in the message.

Here is an example of a script that will read the request message content as XML and write it to a file named for its contents:

$xml = [xml] $message.GetBody()
 
# xml looks like: "<order><orderId>123422</orderId>....</order>"
$name = $xml.order.orderId
 
$xml.get_OuterXml() | set-content "C:\orders\$name.xml"

If the Adapter is used in a two-way, solicit/response send port, the data can be passed back to the BizTalk Application through the response message. The body data stream of the response message is created automatically in the following way:

  • It's possible to write directly to the response stream using the Write-Host cmdlet or by directly calling the Write() and WriteLine() methods in $host.UI.
  • Objects written through Write-Output or returned by the script are fed through the default output formatter in PowerShell and written as text to the response stream.

The script can also interact directly with the response message through the $replyMessage variable. This object has the same methods/properties as the request message object mentioned before, and also adds:

  • AddPart(): This method adds a new, non-body, part to the BizTalk message. It takes as arguments the name of the part (must be unique) and a Stream object with the data.
  • SetProperty(): This method writes a property to the message context. It takes the name, namespace and value of the property.
  • Promote(): This method promoted a property in the message context. It takes the name, namespace and value of the property.

Copyright (c) 2022 /n software inc. - All rights reserved.
/n software Adapters for BizTalk - Version 20.0 [Build 8319]