locked
Macro Querry RRS feed

  • Question

  • Hi ,

    I want the destination file should havename as    *YYYY_MM_DD_HH24_MI_SS_SSS.csv

    I have tried using date time  but its totally different macro please suggest.

    Monday, February 22, 2016 8:37 AM

Answers

  • Hi,

    Without no code effort, the best you can get is in YYYYMMDDhhmmsss format.

    You can use the following macros in the send port file name:

    • %datetime% - Coordinated Universal Time (UTC) date time in the format YYYY-MM-DDThhmmss (for example, 1997-07-12T103508).
    • %datetime_bts2000% - UTC date time in the format YYYYMMDDhhmmsss, where sss means seconds and milliseconds (for example, 199707121035234 means 1997/07/12, 10:35:23 and 400 milliseconds)
    • %datetime.tz% - Local date time plus time zone from GMT in the format YYYY-MM-DDThhmmssTZD, (for example, 1997-07-12T103508+800)

    Thanks to Sandro. Refer: http://social.technet.microsoft.com/wiki/contents/articles/8823.biztalk-server-list-of-macros.aspx

    Solution without Orchestration:

    You can build a pipeline component that set the filename with the structure you wish to, something like :

    public IBaseMessage Execute(IPipelineContext pContext, IBaseMessage pInMsg)
    
    {
        string filename = string.Empty;
        //Place some code here to generate file name
    
        pInMsg.Context.Write("ReceivedFileName", "http://schemas.microsoft.com/BizTalk/2003/file-properties", filename);
    
        return pInMsg;
    
    }


    Then you need to create one send pipeline with the component that you create, and in the send port file configuration, on FILE NAME field put the following text: %SourceFileName%

    Solution with Orchestration:

    As explained by Suleiman you can have your logic for creating file name in expression shape in orchestration and then use message assignment shape (Here you are setting one of the message's context properties so it must be within the scope of the construct message) and set the Custom file name.

    msgOutput(FILE.ReceivedFileName) = customfilename + ".csv";

    or you can have a method on a .NET helper class that contains logic for creating the filename.

    OutgoingMsgName(FILE.ReceivedFileName) = BTSHelper.GenerateOutputFilename();

    Then, in the SendPort configuration you can use the macro %SourceFileName% and it will be replaced with the filename you set in the message's context.

    Again thanks to Sandro. Refer: https://code.msdn.microsoft.com/windowsdesktop/Customize-filename-da8962ad


    Rachit Sikroria (Microsoft Azure MVP)

    Monday, February 22, 2016 10:48 AM
    Moderator

All replies

  • It is not possible to use this format with Macro.

    You need to do this in orchestration by using expression shape in orchestration and create your file name format variable (outboundfilename) and set value at run time

    Then use the following code in Message Assignment Shape

    msgOutbound(FILE.ReceivedFileName)=outboundfilename+".xml";


    When you see answers and helpful posts, please click Vote As Helpful, Propose As Answer, and/or Mark As Answer



    Monday, February 22, 2016 8:57 AM
  • Hi,

    Without no code effort, the best you can get is in YYYYMMDDhhmmsss format.

    You can use the following macros in the send port file name:

    • %datetime% - Coordinated Universal Time (UTC) date time in the format YYYY-MM-DDThhmmss (for example, 1997-07-12T103508).
    • %datetime_bts2000% - UTC date time in the format YYYYMMDDhhmmsss, where sss means seconds and milliseconds (for example, 199707121035234 means 1997/07/12, 10:35:23 and 400 milliseconds)
    • %datetime.tz% - Local date time plus time zone from GMT in the format YYYY-MM-DDThhmmssTZD, (for example, 1997-07-12T103508+800)

    Thanks to Sandro. Refer: http://social.technet.microsoft.com/wiki/contents/articles/8823.biztalk-server-list-of-macros.aspx

    Solution without Orchestration:

    You can build a pipeline component that set the filename with the structure you wish to, something like :

    public IBaseMessage Execute(IPipelineContext pContext, IBaseMessage pInMsg)
    
    {
        string filename = string.Empty;
        //Place some code here to generate file name
    
        pInMsg.Context.Write("ReceivedFileName", "http://schemas.microsoft.com/BizTalk/2003/file-properties", filename);
    
        return pInMsg;
    
    }


    Then you need to create one send pipeline with the component that you create, and in the send port file configuration, on FILE NAME field put the following text: %SourceFileName%

    Solution with Orchestration:

    As explained by Suleiman you can have your logic for creating file name in expression shape in orchestration and then use message assignment shape (Here you are setting one of the message's context properties so it must be within the scope of the construct message) and set the Custom file name.

    msgOutput(FILE.ReceivedFileName) = customfilename + ".csv";

    or you can have a method on a .NET helper class that contains logic for creating the filename.

    OutgoingMsgName(FILE.ReceivedFileName) = BTSHelper.GenerateOutputFilename();

    Then, in the SendPort configuration you can use the macro %SourceFileName% and it will be replaced with the filename you set in the message's context.

    Again thanks to Sandro. Refer: https://code.msdn.microsoft.com/windowsdesktop/Customize-filename-da8962ad


    Rachit Sikroria (Microsoft Azure MVP)

    Monday, February 22, 2016 10:48 AM
    Moderator