BizTalk.PipelineComponents.CustomMacros

Adds custom SendPort macros, works for both Filename and folder

Properties

Name Description
Must Exist Target folder path must exist.
Context Required An error is thrown if the specified Context cannot be found
SSOAffiliate Use SSO Application instead of host user

Macros

If the PipelineComponent is used in any stage in a sendport pipeline, the following custom macros will be available

%IF(#,#,#)%
If the expression (first parameter) is matched in any way the second parameter will be returned or else the last parameter (else) will be returned
Example: outbound transport location is c:\Volvo\Cars\V40\cars.vsc and the macro is Cars_%IF(XC40,SUV,Regular)%.xml then Cars_Regular.xml will be returned.

%TimeStamp(#,#,..)%
Used to modify timestamp much like the Nearest Macro except with TimeStamp macro you can modify multiple placeholders and the complete modified timestamp will be returned.
Example: outbound transport location is \\share\DC\certificates_%TimeStamp([0-9]{8}([0-9]{2})[0-9]{2}([0-9]{2}),5,4)%.xml then macro will return certificates_20230808003032.xml where hour and seconds are modified before returning the complete modified timestamp.

%Nearest(#,#)%
Used to modify timestamp in the filename as sometimes you need to make sure two files has the same timestamp even though they are created in different processes.
Consider two files named certificates_20230808133030.csv and competences_20230808133133.csv and where specification says the timestamp must be the same for both files.
Using the following file pattern %FilePattern([a-z]+_[0-9]{8})%%Nearest(([0-9]{2})[0-9]{2}[.],30)%00.csv the files will be renamed to certificates_20230808133000.csv and competences_20230808133000.csv
First part uses FilePattern macro to extract the beginning of thte filename. Nearest macro picks out the minut part of the datetime and calculates it to the nearest 30 min window (second parameter). In this sample seconds have been hardcoded to 00.

%ParentFolder%
Returnes the parent folder to original source folder.

%FolderRange(#,#)%
Return a folder or folderpath part from incomming file.
Example if original folderpath is \\server\folder1\folder2\folder3\filename.txt
Then %FolderRange(2,2)% returns folder1\folder2
If %FolderRange(2)% is used then folder2 is returned.

Example

%OriginalPath%
Folder structure from incomming file, volume or drive letter excluded. If inboundlocation is D:\Integrations\Incomming\file.txt then the macro returns Integrations\Incomming.

%OriginalFolder%
Returns original folder name. If inboundlocation is D:\Integrations\Incomming\file.txt then the macro returns Incomming.

%FileNameOnly%
Like %SourceFileName% but without the file extension.

%AddDays(#,#)%
Lets you add or subtract day(s) for DateTime.Now. Works like DateTime.Now.AddDays(#).ToString(#)
Examples: %AddDays(1,dd)%, add one day to current datetime
%AddDays(-2,dd)%, substract two days to current datetime

%AddMonths(#,#)%
Lets you add or subtract month(s) for DateTime.Now. Works like DateTime.Now.AddMonths(#).ToString(#)
Examples: %AddMonths(1,mm)%, add one month to current datetime
%AddMonths(-2,mm)%, substract two months to current datetime

%AddYears(#,#)%
Lets you add or subtract day(s) for DateTime.Now. Works like DateTime.Now.AddYears(#).ToString(#)
Examples: %AddYears(1,yyyy)%, add one year to current datetime
%AddYears(-2,yyyy)%, substract two years to current datetime

%UTCAddDays(#,#)%
Lets you add or subtract day(s) for DateTime.UtcNow. Works like DateTime.UtcNow.AddDays(#).ToString(#)
Examples: %UTCAddDays(1,dd)%, add one day to current utc datetime
%UTCAddDays(-2,dd)%, substract one day to current utc datetime

%UTCAddMonths(#,#)%
Lets you add or subtract month(s) for DateTime.UtcNow. Works like DateTime.UtcNow.AddMonths(#).ToString(#)
Examples: %UTCAddMonths(1,mm)%, add one month to current utc datetime
%UTCAddMonths(-2,mm)%, substract two months to current utc datetime

%UTCAddYears(#,#)%
Lets you add or subtract day(s) for DateTime.UtcNow. Works like DateTime.UtcNow.AddYears(#).ToString(#)
Examples: %UTCAddYears(1,yyyy)%, add one year to current datetime
%UTCAddYears(-2,yyyy)%, substract two years to current utc datetime

%UTCDateTime(#)%
Lets you format the current date time as you want it. Works more or less like DateTime.UtcNow.ToString()
Examples: %UTCDateTime(d)%, current day number
%UTCDateTime(yyyy)%, current year
%UTCDateTime(MM)%, current month

%DateTime(#)%
Lets you format the current date time as you want it. Works more or less like DateTime.Now.ToString(#)
Examples: %DateTime(d)%, current day number
%DateTime(yyyy)%, current year
%DateTime(MM)%, current month

%FileDateTime(#)%
Works like the %DateTime% macro but it uses the FileCreationTime instead.

%Context(#)%
Use any value from standard context values
Example %Context(BTS.InterchangeID)% returns the InterchageID of the message.

Available standard Context

Custom Context
Custom context can also be applied by using the prefix CST. A search will be done through all none MS context properties until a match is made.
Distinguished Fields
It is possible to use distinguished fields by adding a filename friendly xpath variant. This is a better alternative then using unnecessary promoted properties.
Example: If the distinguished xpath looks like bellow /[local-name()='Ledger' and namespace-uri()='http://ICC.Company.Schemas']/[local-name()='AccountingDate' and namespace-uri()=''] Filename friendly xpath would be ~Ledger~AccountingDate Final macro would then be %Context(~Ledger~AccountingDate)%

%Folder%
Adds a backslash . This makes it possible to choose any folder bellow the root folder specified by URI.
Example: %DateTime(yyyy)%%Folder%%DateTime(MM)%%Folder%%DateTime(dd)%%Folder%message.xml If the URI is c:\integrations\int0010\ and the current date is 2017-05-04 the final folder and filename will be c:\integrations\int0010\2017\05\04\message.xml
Folder structure will be created if it does not exist.

%ReceivedDateTime(##)%
Works like the %DateTime% macro but it uses the AdapterReceiveCompleteTime instead. To use this macro tracking must be enabled.
%Root%
Returns the root node of a message
%DateTimeFormat([context],[dateformat])%
Example:
%DateTimeFormat(FILE.FileCreated,yyyy)%
%DateTimeFormat(~Invoice~InvoiceDate,yyyy)%
Works like the %DateTime% macro but it works on any context property , promoted or not or distinguished, that contains any value that could be interpreted as a date/time format
Date format yyyyMMdd is also allowed

%FilePattern([regex])% Runs a regex expression on sourcefilename.
Example: If incomming filename is P123789.txt and sendport filename is Q%FilePattern([0-9]+)%.txt, Then outgoing filename would result in Q123789.txt
The component also handle groups in RegEx expression. For example if the expression is "%FilePattern(_([0-9]{3})_)%.pdf" and the filename is "WAP_123_12345.xml" then the result would be "123.pdf".
Only the first RegEx group will be returned.

%FileExtension% Returns the fileextension from sourcefilename.
Example: If incomming filename is P123789.txt then .txt will be returned.