Filename with Incrementing Counter

Home Page Forums BizTalk 2004 – BizTalk 2010 Filename with Incrementing Counter

Viewing 2 reply threads
  • Author
    Posts
    • #25712

      Hi,

      We need to output to an FTP location using the FTP adapter, and implement an incrementing counter for the filname. Filename being RSP<counter> Eg. RSP1, RSP2 with no file extension to OS400. The counter needs to be available from multiple applications that write the file to the same location. Preferably implemented within the orchestration. The way I’ve thought about doing it is using a SQL Server stored procedure to maintain the counter on the autonumber, by writing in this case the purchase order number to the table.

      I’ve seen the methods to update the file name through pipelines, and dynamic send ports, but what would be the best way to maintain the counter?

      Thanks

    • #25713

      Hi,

      You need to save somewhare your counter. Or SQL, or some file (xml for example), if you want to cause availability to many different sources. Every time you create your file (file name) – get the iterator, and promote it by one + save (again in SQL or file). Next application to use that source – will take tha itarator. Sounds OK for me.

      • #25714

        If you had to implement this functionality what would you do?

        Thanks

        • #25717

          Hi,

          In one of my projects we implement such pattern: we need a unique number, which is build of three groups. AA BBB CCCCCCC,

          Where AA is some process type, BBB subprocess type, CCCCCCC – is autoincremental number.

          When I need this number – I pass as parameters AA and BBB, and in stored procedure call to another stored procedure which inserts dummy value to table for autoincrement. (Also you can delete that row after getting number). The autoincremented number is 7 digits.

          When I get that number, I convert is to string, and both received parameters are concatenated (not to get added mathimatically, i.e. 123 45 I want as 12345 and not 168) as strings too. The resullt I convert back to BIGINT (long in .Net, Int64 in BizTalk).

          By this practice I get uniquie numbers, easily and managed. When you create your file – just let this number to be name of your file. If you need to give string name – instead of numeric parameters – add strings.

          • #25725

            Excellent, thanks for the responses.

            Sorry forgot to mention I’m restricted to 10 characters including the prefix. The stored procedure route best fits the requirements.

            Would you normally make the call to the stored procedure through the SQL adapter? Or do you use alternate methods?

            Cheers

            • #25735

              Hi,

              In this special case I use method in external assembly: call method with two parameters AA and BBB and get as response (through DAL) – my identificator.

              If you have no need in some external helpers – (actually I use WCF-SQL adapter – call SQL through generated schemas) – or you can expose as it is most suitable for your architecture.

              If you have distributed envoronment – you can expose it even as web service – availiable for all your “different projects”

      • #25715

        If you want your application to scale, then SQL Server is the best place to do this. Using multi-threaded host instances on multiple machines will require some mechanism for locking your iterator. I have in the past, used a table with a single column and single row  and a stored proc like this:

        DECLARE

         

        @increment INT
        — need an explicit transaction to make the select and update serializable
        SET TRANSACTION ISOLATION LEVEL SERIALIZABLE
        BEGIN
        TRANSACTION
        — ensure that any constraint violations or other errors cause a rollback
        SET XACT_ABORT ON
        — maintain an exclusive lock on the data until the end of the transaction
        SELECT @increment = MAX(Increment) FROM Iterator WITH (TABLOCKX)
        UPDATE SaleId SET Increment = @increment + 1
        SET XACT_ABORT OFF
        COMMIT
        TRANSACTION

         

    • #25716

      Hi.

      I use a GUID in an orchestration to write the file into a separat folder. And the same GUID into a Database so I find the right dataset to the file I read in.

      And I can write each file in the same folder. If you don’t need to use a counter starting by 1 and so on … these are two lines of code in the orchestration.

      In the expression shape use: RSP_GUID = System.GUID.NewGUID();

      In the Message Assignment Shape use: message(FILE.ReceivedFileName) = “RSP” + “RSP_GUID” + “.xml”;

      I hope this helps.

      cheers

      Wolfgang 

Viewing 2 reply threads
  • The forum ‘BizTalk 2004 – BizTalk 2010’ is closed to new topics and replies.