Customer Portal

Creating sequence for a row - RowID

Comments 3

  • Avatar
    Tomas Pavlas
    1
    Comment actions Permalink

    Hi CloverDxNewBie,

    From the information provided, I understand you want to add a new Field to every row called “rowID” with increasing value.

    In this case, the easiest way is very basic coding in MAP component.

    To achieve the row ID field, please, follow the instructions:

    1. Duplicate the Existing metadata from the source file and add a new integer field called rowID.



    2. Add the MAP component to the graph and put the new created metadata on the Output Edge of the MAP.


    3. Open the Transform property of the MAP component, go to the Source card and add this code to the function:
      integer rowID = 1; // Create Integer variable and set it to 1.

      function integer transform() {
            $out.0.* = $in.0.*; // Use Wildcard to assign identical fields.
            $out.0.rowID = rowID; // Assign the variable to the rowID field.
           rowID ++; // increases the rowID by one every record.
      return ALL;
      }

    1. Now if you run the Graph, you should see on the output edge of the MAP component a field rowID with incrementing numbers.


    If you want to achieve more complex rowIDs or use more functionalities associated with sequences, you can use the Sequence property in CloverDX Designer in the Outline section. More about Sequences here.

    I hope this will help, but if you want to change any existing fields based on any rules and don't want to create a new field, could you please be more specific about your goals?

    Best regards, Tom.

  • Avatar
    David Pavlis
    1
    Comment actions Permalink

    Hi,

    From your description of the use-case, it seems to me, that you actually want to populate the field Order. Basically numbering the members of groups - defined by Item values, perhaps  ?

    In that case, the code would need to be modified slightly:

    integer rowID = 1; // Create Integer variable and set it to 1.
    string ItemName = "";

    function integer transform() {
    //check whether we see new group in the input data
    if (ItemName != $in.0.Item){
    rowId = 1; // reset the counter
    ItemName = $in.0.Item; // store the new item group name
    }
          $out.0.* = $in.0.*; // Use Wildcard to assign identical fields.
          $out.0.rowID = rowID; // Assign the variable to the rowID field.
         rowID ++; // increases the rowID by one every record.
    return ALL;
    }

    Note: This code will work only if the data are sorted based on Item field.

  • Avatar
    CloverDxNewBie
    0
    Comment actions Permalink

    Hi Tom - Thank you very much for your input, i did manage to make it work but I think i was not able to explain the problem more clearly, apologies but it gives me an idea.

     

    Hi David - Yes, you got it right, thank you so much, it did work and really appreciated for your time and effort.

Please sign in to leave a comment.