Split Array not working

Hello,

I want to split a field and write it to new fields:

The source of my reformat transformer is:

//#CTL2

// Transforms input record into output record.
function integer transform() {

string[] elements = split($in.0.Field6, “.”);

$out.0.Field1 = $in.0.Field1;
$out.0.Field2 = $in.0.Field2;
$out.0.Field3 = $in.0.Field3;
$out.0.Field4 = $in.0.Field4;
$out.0.Field5 = $in.0.Field5;
$out.0.Field6 = $in.0.Field6;
$out.0.Field7 = $in.0.Field7;
$out.0.Field8 = $in.0.Field8;
$out.0.Field9 = $in.0.Field9;

$out.0.el1 = elements[1];
$out.0.el2 = elements[2];
$out.0.el3 = elements[3];

// $out.0.Field10 = $in.0.Field10;
// $out.0.Field11 = $in.0.Field11;
// $out.0.Field12 = $in.0.Field12;

$out.0.Field13 = $in.0.Field13;
$out.0.Field14 = $in.0.Field14;
$out.0.Field15 = $in.0.Field15;
$out.0.Field16 = $in.0.Field16;
$out.0.Field17 = $in.0.Field17;
$out.0.Field18 = $in.0.Field18;
$out.0.Field19 = $in.0.Field19;
$out.0.Field20 = $in.0.Field20;
$out.0.Field21 = $in.0.Field21;
$out.0.Field22 = $in.0.Field22;
$out.0.Field23 = $in.0.Field23;
$out.0.Field24 = $in.0.Field24;
$out.0.Field25 = $in.0.Field25;
$out.0.Field26 = $in.0.Field26;
$out.0.Field27 = $in.0.Field27;
$out.0.Field28 = $in.0.Field28;
$out.0.Field29 = $in.0.Field29;
$out.0.Field30 = $in.0.Field30;
$out.0.Field31 = $in.0.Field31;
$out.0.Field32 = $in.0.Field32;
$out.0.Field33 = $in.0.Field33;
$out.0.Field34 = $in.0.Field34;
$out.0.Field35 = $in.0.Field35;
$out.0.Field36 = $in.0.Field36;
$out.0.Field37 = $in.0.Field37;
$out.0.Field38 = $in.0.Field38;
$out.0.Field39 = $in.0.Field39;
$out.0.Field40 = $in.0.Field40;
$out.0.Field41 = $in.0.Field41;
$out.0.Field42 = $in.0.Field42;
$out.0.Field43 = $in.0.Field43;
$out.0.Field44 = $in.0.Field44;
$out.0.Field45 = $in.0.Field45;
$out.0.Field46 = $in.0.Field46;
$out.0.Field47 = $in.0.Field47;
$out.0.Field48 = $in.0.Field48;

return ALL;
}

The graph is not working 'cause this error:

Component [Reformat:REFORMAT] finished with status ERROR. (In0: 1 recs, Out0: 0 recs)
Message: Transform failed!
Interpreter runtime exception on line 20 column 26
Caused by: java.lang.ArrayIndexOutOfBoundsException → Attempting to access item 1 from list “elements” of size 0
----------------------- CTL2 snippet -----------------------
20: $out.0.el1 = elements[1];
^^^
----------------------- CTL2 snippet -----------------------
variable “elements” (string) :

literal → “1”

Can someone help?

Kind regards,

Hi Holaketal,
the problem lies in the split() function usage. I understand that your intention was to define the dot character as the delimiter within the split() function. However, since it is a special character it needs to be escaped. More information on that matter can be found here.

string[] elements = split($in.0.Field6, "\\.");

Another option is to define the second argument as a regular expression as suggested by our documentation.

string[] elements = split($in.0.Field6, "[.]");

Kind regards,
Vladi