How to Convert BTXML to Variables in an Action? 追蹤

0
Avatar
Dwight McWilliams

We have a web service integration that prints 3 fields on a label using the print BTXML action. I'd like to add a fourth field that would not be printed on the label, but would contain email address that could be used to set a variable that would be used in a a subsequent send email action as the email address. How could I do this. See below for the BTXML.

<?xml version="1.0" encoding="utf-8"?>
<XMLScript Version="2.0" Name="09232006_103601_Job1" ID="123">
<Command Name="Job1">
<FormatSetup>
          <Format>D:\bt_test\labels\poc-prototype1.btw</Format>
               <PrintSetup>
                              <IdenticalCopiesOfLabel>10</IdenticalCopiesOfLabel>
               </PrintSetup>
               <NamedSubString Name="field1">
               <Value>John Q. Public</Value>
               </NamedSubString>
               <NamedSubString Name="field2">
               <Value>Vendor</Value>
               </NamedSubString>
               <NamedSubString Name="field3">
               <Value>999999999999</Value>
               </NamedSubString>
               <NamedSubString Name="email_address">
               <Value>john.q.public@gmail.com</Value>
               </NamedSubString>
</FormatSetup>
<ExportPrintPreviewToImage ReturnImageInResponse="true">
               <Folder>D:\bt_test\output</Folder>
               <FileNameTemplate>print_preview_%PageNumber%.pdf</FileNameTemplate>
               <ImageFormatType>PDF</ImageFormatType>
               <Colors>btColors24Bit</Colors>
               <DPI>300</DPI>
               <Overwrite>true</Overwrite>
               <IncludeMargins>true</IncludeMargins>
               <IncludeBorder>true</IncludeBorder>
               <BackgroundColor>16777215</BackgroundColor>
</ExportPrintPreviewToImage>
</Command>
</XMLScript>

 

 

4 意見

0
Avatar
Gene Henson
正式評論
評論操作 永久連結

There's no easy way to grab substring values from the XML file, yet. However, there's a relatively easy workaround using PowerShell.

The basic premise is that you'll:

  1. Create an variable in the integration to store the email address (I called it email_address.)
  2. Use Powershell to parse the "Event Data" (which is your initial XML script) to find the email_address Substring
  3. Store that value in the email_address variable
  4. Use that variable in the Send email action

I tested this using the XML file provided above. The below script will work:

[xml] $xml = '%EventData%'
$match = $xml.XMLScript.Command.FormatSetup | % {$_.NamedSubstring} | ? {$_.Name -match 'email_address'}
$match.Value

Line 1:

[xml] $xml = '%EventData%'

This creates a variable ($xml) of XML type and assigns it the value of the EventData variable. Please note the ' around %EventData%. This is sets the input to String type, which is what Powershell needs.

Line 2:

$match = $xml.XMLScript.Command.FormatSetup | % {$_.NamedSubstring} | ? {$_.Name -match 'email_address'}

Here we create a variable to hold the matched data and call it $match. We use dot notation to read down the XML path into the FormatSetup node. Once there, we use '%' to loop through the NamedSubstrings and use '?' to find the Substri

ng named 'email_address'.

Line 3:

$match.Value

We output the value of the $match variable. This is important because the output of the Powershell script will be assigned to a variable, so we only want the actual value.

See the below screenshot for how I've set this up:

Hopefully that makes sense and works for you!

0
Avatar
Matt Dolnik
評論操作 永久連結

Did you ever find a solution for this?

 

Edit: The solution from Gene Henson works. A little annoying how one has to jump through these hoops, but it works! Thanks for the very descriptive response.

0
Avatar
Dwight McWilliams
評論操作 永久連結

No I did not. I came up with a clumsy workaround. Do you know of a solution that I could use to implement my original idea?

0
Avatar
Matt Dolnik
評論操作 永久連結

Yes as I mentioned above, the solution from Gene Henson works for this purpose

登入寫評論。