Resources for IT Professionals > Forums Home > BizTalk Server Forums > BizTalk Server EDI and AS2 > How do I override the UNB sender id segment in an EDIFACT message at runtime
Ask a questionAsk a question
 

AnswerHow do I override the UNB sender id segment in an EDIFACT message at runtime

  • Monday, May 04, 2009 10:05 AMIdar H Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Has Code
    Hi,

    I want to reade the EAN ident from the source XML document in BizTalk, and use it as the sender id in the UNB sebment of the EDIFACT message (ORDERS). The EAN ident is promoted, and is available in the send pipeline.
    I have tried to make a custom pipeline, where I read the promoted property, and as far as I can see, I must put it in the propery "SenderID" with the name space "http://schemas.microsoft.com/BizTalk/2006/edi-properties". But when I try to promote the property, I get the exception "Loading property information list by namespace failed or property not found in the list". It seems like the property schema for the namespace "http://schemas.microsoft.com/BizTalk/2006/edi-properties" is missing.

    Her is the code for the custom send pipeline:
    private IBaseMessage ExecuteInternal(IPipelineContext pContext, IBaseMessage pInMsg)
      {
          WriteToTrace("Begin ExecuteInternal()");
    
          string ReadContextPropName = "EANIdent";
          string ReadContextPropNamespace = "http://LV_EDI.PropertySchema.PropertySchema";
          string SetContextPropName = "SenderID";
          string SetContextPropNamespace = <a href="http://schemas.microsoft.com/BizTalk/2006/edi-properties">http://schemas.microsoft.com/BizTalk/2006/edi-properties</a>;
      
     
          try
          {
    
              WriteToTrace(string.Format("Reading property {0}:{1}", ReadContextPropName, ReadContextPropNamespace));
    
              //Read from context                  
              object val = pInMsg.Context.Read(ReadContextPropName, ReadContextPropNamespace);
    
              //Write to the context
              if (val != null)
              {
                  WriteToTrace(string.Format("Property Exists {0}:{1}", ReadContextPropName, val.ToString()));
    
                  WriteToTrace(string.Format("Writing {0}:{1}:{2}", SetContextPropName, SetContextPropNamespace, val.ToString()));
    
                  pInMsg.Context.Write(SetContextPropName, SetContextPropNamespace, val.ToString());
                  pInMsg.Context.Promote(SetContextPropName, SetContextPropNamespace, val.ToString());
              }
              else
                  WriteToTrace(string.Format("{0} Property Does not exist.", ReadContextPropName));
          }
          catch (Exception ex)
          {
              // Do not fail the pipeline if we cannot archive
              // Just log the failure to the trace listener
              WriteToTrace(ex);
          }
      
          WriteToTrace("End   ExecuteInternal()");
      
          //Clone the message and return
          return pInMsg;
      
      }<br/>
    

    Where can I get the property schema for this name space? Or should I solve it using another method?



    Thanks.

Answers

  • Monday, May 04, 2009 3:05 PMGyan Prakash[MSFT] Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Hi,
        For Biztalk server 2006 R2 if you want to override then in custom component you need to write yourself the property and value in the file.
    But in BTS2009 it's a new functionality that if you will promote "OverrideEDIHeader" context property as true then Biztalk will override the promoted properties and it will come in output message.

    Thanks
    Gyan
    If this answers your question, please mark it as "Answered".
    • Marked As Answer byIdar H Thursday, May 07, 2009 1:47 PM
    •  

All Replies

  • Monday, May 04, 2009 10:20 AMGyan Prakash[MSFT] Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Has Code
    Hi,
        You can get property schema for this name space in the Biztalk edi application's Schema lists. The name of the schema is EdiOverride.edi_properties .
    In this schema you can see which properties you can override. And the exception ("Loading property information list by namespace failed or property not found in the list" ) you are getting may be becuse of following reasons:
    1- In your Biztalk application you did not gave the reference of Biztalk EDI application. So add the reference of Biztalk EDI application to your application.
    2- Biztalk EDI/AS2 is not configured properly.



    Thanks
    Gyan
    If this answers your question, please mark it as "Answered".
  • Monday, May 04, 2009 10:40 AMIdar H Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi,
    The application has a reference to BizTalk EDI Application.
    But i can't find the schema EdiOverride.edi_properties in the schemas list for BizTalk EDI Applications. Do you know why it's missing, and what can I do to get it there?

    Thanks
    Idar
  • Monday, May 04, 2009 11:17 AMGyan Prakash[MSFT] Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi,
        Which version of Biztalk are you using? If you are using BTS 2009 then it should be here. Are you sure your Setup and configuration went fine?


    Thanks
    Gyan
    If this answers your question, please mark it as "Answered".
  • Monday, May 04, 2009 11:19 AMIdar H Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    I use BizTalk Server 2006 R2, and as far as I know, the setup went fine.

    Idar
  • Monday, May 04, 2009 11:38 AMGyan Prakash[MSFT] Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi,
       I think you are only promoting the properties. I confused that you told override. So if you want to promote context properties the you need schema EDI.PropertySchema with namespace http://schemas.microsoft.com/Edi/PropertySchema . Just check it in your EDI application that it is present or not?



    Thanks
    Gyan
    If this answers your question, please mark it as "Answered".
  • Monday, May 04, 2009 12:10 PMIdar H Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Let me try to explain what I want to do.

    In EDI Properties for the sending party (BTS Admin Console), in the UNB Segment Definition, the UNB2.1 (Identification) has a given value. However, I want to change this value at runtime, to the value given in the source document from the ERP system. This value is promoted as EANIdent in the namespace http://LV_EDI.PropertySchema.PropertySchema.
    I have made a custom pipeline as described above, where I want to change the appropriate property to make the EDI assembler to give the UNB2.1 segment the address provided in the EANIdent property in stead of the hardcoded one in the BTS Admin Console.

    I have tried to promote the property DestinationPartySenderIdentifier in the namespace http://schemas.microsoft.com/Edi/PropertySchema. When I check the context of the outgoing message, the property is present and has the correct value, but the UNB2.1 segment has still the value given in the BTS Admin Console.

    Then I looked at the properties in the context of the outgoing message, and found the earlier mentioned property SenderId in namespace http://schemas.microsoft.com/BizTalk/2006/edi-properties..

    The schema EDI.PropertySchema is present in the BizTalk EDI Application, and there is a reference from my EDI application to this application.

    So, the main question is, how do I change the UNB2.1 segment in the outgoing EDI (EDIFACT) message to a given value at runtime?

    Thanks,
    Idar
  • Monday, May 04, 2009 3:05 PMGyan Prakash[MSFT] Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Hi,
        For Biztalk server 2006 R2 if you want to override then in custom component you need to write yourself the property and value in the file.
    But in BTS2009 it's a new functionality that if you will promote "OverrideEDIHeader" context property as true then Biztalk will override the promoted properties and it will come in output message.

    Thanks
    Gyan
    If this answers your question, please mark it as "Answered".
    • Marked As Answer byIdar H Thursday, May 07, 2009 1:47 PM
    •  
  • Thursday, May 07, 2009 1:47 PMIdar H Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi,

    Now I have solved it by editing the EDIFACT message, and it works fine.

    Thanks, Idar
  • Monday, November 16, 2009 8:34 AMRain_MS Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi,

    I am running to the same requirement and have no idea how to achieve this.
    Could you please share with me in detail how to do it?

    THANZ a lot!
  • Wednesday, February 10, 2010 9:55 AMMiguel Muñoz Gonzalez Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi,
    I have a problem like you. My problem is that I have several shipments of XML messages that are then converted to a single EDI format. When writing the UNB header is written with information that has been customized in the Administration Console for the Party in particular.
    What I want is to change the parameter UNB2.1 with a different ID each time.
    You could send your solution in detail. Thank you,

    Miguel
  • Tuesday, March 16, 2010 8:20 AMWell0549 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Could you post a code sample of this ?

    I have to meet the same requirement and I am a little unsecure of how to do it.........
    Well0549, Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread
  • Wednesday, March 17, 2010 7:33 AMIdar H Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Has Code
    Hi

    Here are som sample code for a sending pipeline, insert it after the EDI assembly int the custom pipeline. In this sample, the UNB2.1 is located in the promoted propery EANIdent, but you can use whatever you want.

            public IBaseMessage Execute(IPipelineContext pc, IBaseMessage inmsg)
            {
                //Stream to read the incoming stream
                Stream originalStrm;
                originalStrm = null;
    
                //String to save the incoming Stream
                string strIncoming = null;
    
                //Creating a memory stream to send the ouptut at the end
                MemoryStream memStream;
                memStream = new MemoryStream();
    
                // The property to read
                string ReadContextPropName = "EANIdent";
                string ReadContextPropNamespace = "http://LV_EDI.PropertySchema.PropertySchema";
    
                try
                {
                    //Creating an instance for incoming Stream so that we can process it.
                    IBaseMessagePart bodyPart = inmsg.BodyPart;
    
                    if (bodyPart != null)
                    {
                        // Read the promoted property
                        object val = inmsg.Context.Read(ReadContextPropName, ReadContextPropNamespace);
                        if (val != null)
                        {
    
                            // Getting orignal stream
                            originalStrm = bodyPart.GetOriginalDataStream();
                            originalStrm.Seek(0, System.IO.SeekOrigin.Begin);
    
                            //Stream reader to read the incoming stream
                            StreamReader sr = new StreamReader(originalStrm, Encoding.Default);
    
                            //reading stream into string...to add code from here to pipeline
                            strIncoming = sr.ReadToEnd();
    
                            int startPos = strIncoming.IndexOf('+', 19) + 1;        // Find the start position of the UNB2.1 segmeng
                            int endPos = strIncoming.IndexOf(':', startPos);        // Find the end posistion
    
                            // Write the new value
                            strIncoming = strIncoming.Substring(0, startPos) + val.ToString() + strIncoming.Substring(endPos);
    
                            //Saving document to memory stream.
                            Encoding targetEncoding = Encoding.GetEncoding("iso-8859-1");
                            memStream.Write(targetEncoding.GetBytes(strIncoming),0,strIncoming.Length);
                            memStream.Seek(0, SeekOrigin.Begin);
    
                            //Change the data
                            bodyPart.Data = memStream;
                        }
                    }
                    return inmsg;
    
                }
                catch (Exception ex)
                {
                    System.Diagnostics.EventLog.WriteEntry("LV_Edi_AxOrder_Pipeline", ex.Message, System.Diagnostics.EventLogEntryType.Error);
                    System.Diagnostics.EventLog.WriteEntry("LV_Edi_AxOrder_Pipeline", strIncoming, System.Diagnostics.EventLogEntryType.Error);
                    return null;
                }
            }
    
    
  • Wednesday, March 17, 2010 7:34 AMIdar H Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Proposed Answer
    Please see the thread for your answer.
    • Proposed As Answer byWell0549 Thursday, March 18, 2010 8:49 AM
    •