Field length check in Transform script

SK41
Giga Guru

Hi,

I  have a requirement in transform map where  i  have to reject  the record or ignore that particular string field if the  value  in  that  string field exceeds the length  of the field. This data is  coming  through excel  into my  instance table.

Please help me in this regard asap.

Thanks in Advance!     

1 ACCEPTED SOLUTION

asifnoor
Kilo Patron

Hi,

In the transform map, click on the source field whose length you wanted to check.

if(source.u_your_field.toString().length>7) {

ignore=true;

}

Note: you need to mention the right field name and length you wanted to check in the code.

Mark the comment as correct/helpful if it helps to solve the problem.

View solution in original post

15 REPLIES 15

Hi,

You can create a system property and can put the length there.

Go to system properties, create new and there give the unique name for your field and mention the value under value field. select type as integer.

Then in your script, you can fetch the value like this.

var max_length = gs.getProperty("your_property_name");

if(source.u_your_field.toString().length>max_length) {

ignore=true;

}

Mark the comment as helpful if it helps.

The script I provided does this for you. Rather than static code, it dynamically gets the source field value length

SK41
Giga Guru

if i have to do this for other fields too each having different lengths, do i need to create new system property for each field length check?

Yes, If the lengths vary. 

or you can use a string field and separate each length by comma. Have them stored in 1 specific order.

Then in your script, you can fetch the values like this

var max_length = gs.getProperty("your_property_name").toString().split(",");

if(source.u_your_field.toString().length>max_length[0]) {

ignore=true;

}

NOTE: max_length[0] refers to 1st field length. Similalry if you wnat 4th field, then use max_length[3]

Mark the comments as helpful if it helps.