cancel
Showing results for 
Search instead for 
Did you mean: 

Using global variables to generate sequence number.

Former Member
0 Kudos

Hi All,

I have a scneario where in the target structure looks like following.

StoreService is a node and SequenceNbr is a field.

Whenever the node StoreService is created, the SequenceNbr should be generated like 1,2,3 and so on..

Header

StoreService 0..1

SequenceNbr 1..1

StoreService 0..1

SequenceNbr 1..1

StoreService 0..1

SequenceNbr 1..1

StoreService 0..1

SequenceNbr 1..1

I have written a UDF with global variable that takes care of the SequenceNbr generation.

It is working fine for 5-6 StoreService.

And after that the SequenceNbr are getting random values.

Please provide your pointers.

Regards,

Rashi

Accepted Solutions (0)

Answers (2)

Answers (2)

markangelo_dihiansan
Active Contributor
0 Kudos

Hello,

StoreService is a node and SequenceNbr is a field.

What is your logic in generating the store service? Can you just use index e.g


Logic for generating StoreService -> index: 1,1 -> splitByValue:eachValue -> SequenceNbr

Regards,

Mark

Former Member
0 Kudos

The Header node is repeating itself.

So for the output should look as below

Header

StoreService

SequenceNbr 1

StoreService

SequenceNbr 2

StoreService

SequenceNbr 3

Header

StoreService

SequenceNbr 1

StoreService

SequenceNbr 2

StoreService

SequenceNbr 3

StoreService

SequenceNbr 4

Header

StoreService

SequenceNbr 1

StoreService

SequenceNbr 2

and so on..

Former Member
0 Kudos

Hi,

You can use 'Index' standard function to achieve the logic. Select Reset index to initial value with each new context.

So whenver you have the StoreService node, sequenceNbr value starts with 1.

Thanks & Regards,

Sunitha

markangelo_dihiansan
Active Contributor
0 Kudos

Hello,

Header

StoreService

SequenceNbr 1

StoreService

SequenceNbr 2

StoreService

SequenceNbr 3

Header

StoreService

SequenceNbr 1

StoreService

SequenceNbr 2

StoreService

SequenceNbr 3

StoreService

SequenceNbr 4

I'm guessing the context change to generate store service will look like this


storeservice
storeservice
storeservice
CC
storeservice
storeservice
storeservice
storeservice

Then you can use index, in the properties though, specify to restart indexing per context change. The mapping will remain the same


source -> index:1,1 -> splitByValue:eachValue -> SequenceNbr

Hope this helps,

Mark

former_member181985
Active Contributor
0 Kudos

write one more UDF which basically resets the counter/sequence number to 0 whenever it creates Header node.

Object obj = container.getParameter("SeqNo");

Integer i;

if (obj == null)

i = new Integer(0);

else

i = (Integer) obj;

container.setParameter("SeqNo", i)

return ""; //return a; where a is input from source to create enough header contexts

Former Member
0 Kudos

Hi Praveen,

I had used the following approach.

1.) Declared the global variable 'inp' in Attributes & Methods.

2.) UDF 'Initialization' to reset the value 'inp' to 0 for every new Header being created.

inp = 0;

return "";

3.) UDF 'IncrementIndex' to increment the value of 'inp' for every new StoreService to be assigned to SeqNbr.

inp++;

return Integer.toString(inp);

The above UDF gave the correct output uptil 5-6 StoreService. But after that, it is generating random no.s.

Can you please explain where am I going wrong with this approach?

Regards,

Rashi

former_member181985
Active Contributor
0 Kudos

try with this sample code,

Object obj = container.getParameter("SeqNo");

Integer i;

if (obj == null)

i = new Integer(0);

else

i = (Integer) obj;

i = new Integer(i.intValue() + 1)

container.setParameter("SeqNo", i)

return i.toString();