# Creating sequence for a row - RowID

**URL:** <https://forum.cloverdx.com/t/creating-sequence-for-a-row-rowid/2147>\
**Category:** CloverDX Platform\
**Created:** [September 19, 2023, 11:14am UTC](https://forum.cloverdx.com/t/creating-sequence-for-a-row-rowid/2147 "2023-09-19T11:14:47Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![CloverDxNewBie](https://avatars.discourse-cdn.com/v4/letter/c/d07c76/32.png) [@CloverDxNewBie](https://forum.cloverdx.com/u/CloverDxNewBie)\
**Post date:** [September 19, 2023, 11:14am UTC](https://forum.cloverdx.com/t/creating-sequence-for-a-row-rowid/2147/1 "2023-09-19T11:14:47Z")

</div>

Dear Support, is there any example to generate sequential values and assigning it to row as row id after sorting the data, for example:

| Item | ItemColor | Location | Order |
| --- | --- | --- | --- |
| Prod 1 | Blue | Web | 1 |
| Prod 2 | Red | Web | 1 |
| Prod 2 | Blue | Web | 2 |
| Prod 3 | Green | Web | 1 |
| Prod 3 | Blue | Web | 2 |
| Prod 3 | Red | Web | 3 |
| Prod 3 | Blue | Web | 4 |

In the above, Prod 1 has only one color “Blue” so order is 1

Prod 2 has 2 values so the order is 1 and 2

Prod 3 has 4 colors so the order is 1,2,3 & 4.

Kind regards,

---

<div class="post-metadata">

**Author:** ![Tomas\_Pavlas](https://yyz1.discourse-cdn.com/flex007/user_avatar/forum.cloverdx.com/tomas_pavlas/32/170_2.png) [@Tomas\_Pavlas](https://forum.cloverdx.com/u/Tomas_Pavlas)\
**Post date:** [September 21, 2023, 7:31am UTC](https://forum.cloverdx.com/t/creating-sequence-for-a-row-rowid/2147/2 "2023-09-21T07:31:18Z")

</div>

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.  
 ![](https://canada1.discourse-cdn.com/flex007/uploads/cloverdx1/original/1X/2a8d28c8b6e4153ea5daa28005b64c757a809c67.png)
2. Add the **MAP** component to the graph and put the new created metadata on the Output Edge of the **MAP**.  
 ![](https://canada1.discourse-cdn.com/flex007/uploads/cloverdx1/original/1X/961031a52de94ffbe13321c4c3f4681f2f17d411.png)
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.  
 ![](https://canada1.discourse-cdn.com/flex007/uploads/cloverdx1/original/1X/4d19e6f4879f676a8543da8bb78fe4165ed478ea.png)

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_](https://doc.cloverdx.com/latest/designer/sequences.html)_._

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.

---

<div class="post-metadata">

**Author:** ![David\_Pavlis1](https://yyz1.discourse-cdn.com/flex007/user_avatar/forum.cloverdx.com/david_pavlis1/32/67_2.png) [@David\_Pavlis1](https://forum.cloverdx.com/u/David_Pavlis1)\
**Post date:** [September 24, 2023, 5:10pm UTC](https://forum.cloverdx.com/t/creating-sequence-for-a-row-rowid/2147/3 "2023-09-24T17:10:53Z")

</div>

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._

---

<div class="post-metadata">

**Author:** ![CloverDxNewBie](https://avatars.discourse-cdn.com/v4/letter/c/d07c76/32.png) [@CloverDxNewBie](https://forum.cloverdx.com/u/CloverDxNewBie)\
**Post date:** [October 23, 2023, 7:57am UTC](https://forum.cloverdx.com/t/creating-sequence-for-a-row-rowid/2147/4 "2023-10-23T07:57:43Z")

</div>

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.
