cancel
Showing results for 
Search instead for 
Did you mean: 

UDF issue about record counter

Former Member
0 Kudos

Hi gurus,

i want to create the auto-increasing counter for the records in my message mapping.But during my testing,the sequence number always pops up "1" which means it don't calculate based on the cache value. The code as below:

=========================================================================================

public String Counter(Container container){

GlobalContainer gcontainer = container.getGlobalContainer();

Object o = gcontainer.getParameter("counter");

Integer iSeq ;

if(o == null)

{

iSeq = new Integer(1);

}else

{

iSeq = (Integer)o;

iSeq = new Integer(iSeq.intValue() + 1);

gcontainer.setParameter("counter",iSeq);

}

return iSeq.toString();

}

==========================================================================================

can anyone shed light on this?

Thanks in advance.

Accepted Solutions (1)

Accepted Solutions (1)

0 Kudos

Hi Rajesh,

Small change in your code. please see the below code

public String Counter(Container container){

GlobalContainer gcontainer = container.getGlobalContainer();

Object o = gcontainer.getParameter("counter");

Integer iSeq ;

if(o == null)

{

iSeq = new Integer(1);

gcontainer.setParameter("counter",iSeq);

}else

{

iSeq = (Integer)o;

iSeq = new Integer(iSeq.intValue() + 1);

gcontainer.setParameter("counter",iSeq);

}

return iSeq.toString();

}

Regards,

Naga.

Former Member
0 Kudos

thanks nagababumathi ,

from your advice,i have implemented the counter function in various approach actually.

Thank you all again.

Any kind from your opinion are appreciated.

Cheers.

Rajesh.

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi Rajesh,

Have you solved the issue?? same issue we are facing even using UDF the value was not incrementing for the next execution. Could you suggest what changes need to be done.

Thanks In Advance.

Regards,

Anusha Penneru

Former Member
0 Kudos

As Harish has already mentioned, use the index function for this. Make sure that you remove all context changes by either selecting the context at the root level or using the RemoveContext function before using the index function

Harish
Active Contributor
0 Kudos

Hi Rajesh,

You can use the standard funtion index for this requirement.

Regards,

Harish

Former Member
0 Kudos

Yes, i know that standard function can be implemented the requirement/

But i just want to write the UDF code to implement that a another way, Can you guide me how wo solve the issue?

former_member854360
Active Contributor
0 Kudos

Hi Rajesh,

You can use this simple UDF to achive your requirement.

This is an Advance UDF with execution type all values of Queue

Here input value is input field for which you want to create sequence number in target.

public void generateSequenceNo(String[] Value, ResultList result, Container container) throws StreamTransformationException{

int temp = 1;
// Loop to assign sequence numbers starting from 1
for (int i = 0;i<Value.length;i++)
{

	result.addValue(++temp);

}
}

former_member854360
Active Contributor
0 Kudos

Hi rajesh

\

anothr smart option.

in meesage mapping editor under function tab

add the below code

Under Attributes and Methods Integer iSeq ;

Under init iSeq = new Integer(0);

Then UDF:

public String Counter(Container container){


iSeq = iSeq+1;
return iSeq.toString();
}

Edited by: Debashish on Jul 15, 2011 9:09 AM

Former Member
0 Kudos

Thanks,Debashish

It's really a fantastic option using global variable.

I'm also want to implement that via such as container.getParameter() method...

Could you guide me that way as well?

Former Member
0 Kudos

Thanks,Debashish

It's can be achived by using advance resultList according to the whole queue value and do the counting job.

I'm also want to implement that via such as container.getParameter() method...

Could you guide me that way as well?

former_member854360
Active Contributor
0 Kudos

Hi Rajesh,

Please see the Michal_Krawczyk_PIXI blog about GlobalContainer sequence number.

/people/michal.krawczyk2/blog/2005/03/04/globalcontainer--in-graphical-mapping-xi