Friday, November 7, 2008

Splitting multi-valued variables in TDI

In many cases, we have an entry with multiple values (separated by comma, for example), and we need to split those values and process one at a time.

Assuming there is an entry with the following values:

10.4.128.24, 10.4.128.160, 10.4.128.161, 10.4.128.220, 10.4.128.227, 10.4.128.229, 10.4.128.231, 10.4.128.232, 10.4.128.209, 10.4.129.24

Here are the steps to process each value at a time:

  • In your AL, add a script component with the following code
    multiValued = work.getString ("MultiValued");

    task.logmsg ("multi valued: " + multiValued);

    tokenizer = new java.util.StringTokenizer (multiValued, ",");
    work.setAttribute ("values", null);

    while (tokenizer.hasMoreTokens ()) {
    token = tokenizer.nextToken ();
    task.logmsg ("value: " + token);
    work.addAttributeValue ("values", token);

    }
  • Add a Loop to your AL
  • In the Loop, select Attribute Value Loop
  • In the Work Attribute Name, type values (which matches the Work Entry defined in the code above)
  • In the Loop Attribute Name, type value
  • Inside the loop, you'll have the value Work Entry with a single value to process.
That's it!

1 comment:

Anonymous said...

Excellent, that is exactly what I was looking for. Thanks a lot!