How to customize BizTalk EDI header data section at runtime

Take EDI 855 as example

LAI TOCA
2 min readJul 31, 2023
Photo from: https://www.biztalk360.com/blog/pdf-decoder-pipeline-component-for-biztalk-server/

Image that we are running a GPU manufacturing factories. Our customer would like to purchase some chips via EDI transactions. After we received EDI 850 for the order. Then we need ack the order with correspond EDI 855 for the order under different branches (of company) that represent by sector GS02 (Sender ID). The traditional approach that we could create multiples target namespace (same structure 855 type) and setting the diverse GS02 under BizTalk Agreement -> Envelopes as below:

Agreement -> Envelopes

The method was quite straightforward but if we could handle the case at run time inside our BizTalk orchestration ?

Certainly, yes we could did a little tricky on the creation of EDI message. First we could store our GS02 (Sender ID) from somewhere as data source (usually in DB). Next, inside the orchestration we could retrieve the sender ID information from the “Receive” port of BizTalk. Finally just overwrite the EDI header under the “Message Assignment”.

Orchestration
// Inside the Message Assigment of Orchestration

// Retreive the MessageID, SenderID
// from data source (DB) and assign to variable
strMessageID = MSG_LOB_PO_HEADER.MESSAGE_ID;
strSenderID = MSG_LOB.PO_HEADER.SENDER_ID;

strXML = MSG_TEMP.OuterXml.ToString();

MSG_EDI855_TARGET = new System.Xml.XmlDocument();
MSG_EDI855_TARGET.LoadXml(strXML);

// overwrite EDI header GS02 @ run-time
// strSenderID was coming from database
MSG_EDI855_TARGET(EdiOverride.OverrideEDIHeader) = true;
MSG_EDI855_TARGET(EdiOverride.GS02) = strSenderID;

// setup filename
MSG_EDI855_TARGET(FILE.ReceivedFileName) = strMessageID;

The 2 tip here be awareness:

- Please import and reference the namespace “Microsoft.BizTalk.Edi.BaseArtifacts”. (usually under the path: “C:\Program Files (x86)\Microsoft BizTalk Server”)

- EdiOverride.OverrideEDIHeader should enable (set to true).

Reference

--

--

LAI TOCA

Coding for fun. (Either you are running for food or running for being food.)