Hello,
I am trying to create a unique ID using a specific Date format.
In my graph I use a reformat component.
In my reformat component I have some inputs 2 of them are:
- $in.0.Total --> This is the total number of records that I am passing through.
- $in.0.ID --> This record is null
What I did I created a While statement that I wanted to create a unique value in very spicific way and in that while loop to assign a each ID to the record.
The following is the while statement is what I used in the reformat:
integer i;
integer a;
integer b=getMillisecond(today(),"GMT");
integer c = $in.0.Total;
while (i != c) {
$out.0.ID =""+ getYear(today(),"GMT")+getMonth(today(),"GMT")+getDay(today(),"GMT")+getHour(today(),"GMT")+getMinute(today(),"GMT")+getSecond(today(),"GMT")+b;
i++;
b++;
};
The logic into this is that I create an ID using the format (Year,Month,Day,Hour,Minutes,Seconds,Milliseconds)
I set a parameter b that is the Milliseond.
A parameter i that will start from - and go increment by 1 until I get all the values inserted into my IDs.
A parameter c that is equal into the number of records I have so I can run the while statement that many times.
My expectation is that if I had 20 records it will get the first id = 201931232756954 and then it will increment by 1 for all the other records.
My problem is that when I use this while statement is that is assigning the same value (first ID) into all the records.
How to change this transformation in order to make it work as I want?
I attached an example of my output.
I am trying to create a unique ID using a specific Date format.
In my graph I use a reformat component.
In my reformat component I have some inputs 2 of them are:
- $in.0.Total --> This is the total number of records that I am passing through.
- $in.0.ID --> This record is null
What I did I created a While statement that I wanted to create a unique value in very spicific way and in that while loop to assign a each ID to the record.
The following is the while statement is what I used in the reformat:
integer i;
integer a;
integer b=getMillisecond(today(),"GMT");
integer c = $in.0.Total;
while (i != c) {
$out.0.ID =""+ getYear(today(),"GMT")+getMonth(today(),"GMT")+getDay(today(),"GMT")+getHour(today(),"GMT")+getMinute(today(),"GMT")+getSecond(today(),"GMT")+b;
i++;
b++;
};
The logic into this is that I create an ID using the format (Year,Month,Day,Hour,Minutes,Seconds,Milliseconds)
I set a parameter b that is the Milliseond.
A parameter i that will start from - and go increment by 1 until I get all the values inserted into my IDs.
A parameter c that is equal into the number of records I have so I can run the while statement that many times.
My expectation is that if I had 20 records it will get the first id = 201931232756954 and then it will increment by 1 for all the other records.
My problem is that when I use this while statement is that is assigning the same value (first ID) into all the records.
How to change this transformation in order to make it work as I want?
I attached an example of my output.
-
Hello Evangeloslef,
I might be missing some crucial parts of your use case but from what you described, it seems there might be an easier way of how to approach this challenge. I am also a little bit on the fence as to how exactly the input data looks like. Therefore, I took the liberty of manufacturing a set of examples demonstrating various scenarios:- incrementID.grf
I assume that there is a set of data without IDs and the goal is to set the ID on each record with an incremental number at the end. Worth noting is that I took advantage of the sequences feature in CloverDX. - incrementID2.grf
This is the same idea but without using sequences but a simple incrementing variable inside the Reformat component instead. - incrementID3.grf
I don't assume the set of data and I only work with the total count. I am using the Normalizer component to create multiple IDs with the desired format based just on the input count of records. - incrementID4.grf
This is the fourth scenario that I perceived as possibly desired from your question. Again, I assume a set of data without IDs and I also assume that you would want to increment the millisecond "suffix" at the end of the ID. Worth noting is the transformation code of the Reformat component where I resolve the milliseconds separately and then add up an incremental number for each record.
Kind regards, - incrementID.grf
-
Hello Vladimir Barton,
That was really helpful.
Actually incrementID2 is what I needed and I now understand better how to use it next time.
Thank you for the help,
Evangelos Lefkonikiatis
Please sign in to leave a comment.
Comments 2