Integration

Get Involved. Join the Conversation.

Topic

    Sajeena K S
    Generate unique number while reading in segments
    Topic posted May 17, 2019 by Sajeena K SRed Ribbon: 250+ Points, tagged Cloud, ERP Cloud, Integration, Mapping, PaaS, xml 
    97 Views, 7 Comments
    Title:
    Generate unique number while reading in segments
    Summary:
    How to generate a unique number in the xslt while reading the file using segment read from stage
    Content:

    Hi, 

    I am reading an invoice file using the AIC stage read activity. Since the file size is more than 10MB we need to read the file in segments. While transforming the data, it is required to generate a unique invoice id for each line. Tried to concatenate the instance id with the position. But since each segment will have 200 records each, the position is getting repeated in the segments and hence getting unique constraint issue. 

    Any suggestion is appreciated. 

    Thanks in advance.

    Sajeena

    Version:
    19.2.1.0.0

    Comment

     

    • Hemanth Lakkaraju

      What is the dataType for invoiceId? Can you use generate-id() or generate-guid() from XSLT?

      • Sajeena K S

         

        InvoiceId is of number type hence cannot use generate-id() or generate-guid(). For now i used another variable SegmentBatchId and increments it by 1 after each segment read. I am concatenating BatchId, SegmentId and position. So that always it is unique. As of now it is working as expected.

         

        • Roop Katamneni

          Hi, 

          Even, I have encountered the similar issue, where each rec should be inserted with unique ID. currently, I have tried concatenating the ( postion, batchid, position ) . But this fails at 1st record of 111th batch which is 11111 and is similar to 11th batch of 1st record, 

          So, how do i get the segmentID and pass it accordingly, so that the number is unique .

          • Hemanth Lakkaraju

            This is what you can do, assuming you have a for-each in XSLT inside chunk read. Initiate a variable with batchId as 0 before stage read chunk. Inside stage read chunk and when you map the chunk response to target service, for Unique ID, you can use ($batchId*200)+position(). At the end of the chunk read, you can increment batchId to $batchId+1. This will increment the batchId for each chunk.

    • Hemen Shah

      instead of concanating position with instance id , you can use instance id and increment by 1 every time. for Inventory transaction we have same requirement to generate unique transaction_id, we used this approach and it worked fine for us.

      • Sajeena K S

        Thanks for the suggestion Hemen. In my case, the invoiceId should not be existing in ERP cloud hence using a large number by concatenating. For now i used another variable SegmentBatchId and increments it by 1 after each segment read. I am concatenating BatchId, SegmentId and position. So that always it is unique. As of now it is working as expected.