PDA

View Full Version : Javascript not trimming down data length



kettle_anonymous
04-20-2006, 09:05 AM
I am new to Kettle and I am trying to figure this stuff out. Can someone explain to me how to do something simple? What I am trying to do is open an Excel spreadsheet, run the records through a transformation to make the columns a certain length, then load those records into an oracle database.

Using Spoon, I have tried this:

Step 1) Input -> Excel File
Step 2) Transform -> Select Values (to set up the new column names and lengths)
Step 3) Transform -> Javascript Value (use substr example I found in other posts)
Step 4) Output -> Table output

Here is my Javascript code, I know it looks like overkill but without the if statements, I would encounter Index out of range errors every time a column value was less than the column size:

if (ITEMNUM.length > ITEMNUM.getLength())
{
ITEMNUM = ITEMNUM.substr(0,ITEMNUM.getLength());
}

if (CLASSSTRUCTUREID.length > CLASSSTRUCTUREID.getLength())
{
CLASSSTRUCTUREID = CLASSSTRUCTUREID.substr(0,CLASSSTRUCTUREID.getLength());
}

if (ATTRIBUTE1.length > ATTRIBUTE1.getLength())
{
ATTRIBUTE1 = ATTRIBUTE1.substr(0,ATTRIBUTE1.getLength());
}

if (ATTRIBUTE2.length > ATTRIBUTE2.getLength())
{
ATTRIBUTE2 = ATTRIBUTE2.substr(0,ATTRIBUTE2.getLength());
}

if (ATTRIBUTE3.length > ATTRIBUTE3.getLength())
{
ATTRIBUTE3 = ATTRIBUTE3.substr(0,ATTRIBUTE3.getLength());
}

if (ATTRIBUTE4.length > ATTRIBUTE4.getLength())
{
ATTRIBUTE4 = ATTRIBUTE4.substr(0,ATTRIBUTE4.getLength());
}

if (ATTRIBUTE5.length > ATTRIBUTE5.getLength())
{
ATTRIBUTE5 = ATTRIBUTE5.substr(0,ATTRIBUTE5.getLength());
}

if (ATTRIBUTE6.length > ATTRIBUTE6.getLength())
{
ATTRIBUTE6 = ATTRIBUTE6.substr(0,ATTRIBUTE6.getLength());
}

if (ATTRIBUTE7.length > ATTRIBUTE7.getLength())
{
ATTRIBUTE7 = ATTRIBUTE7.substr(0,ATTRIBUTE7.getLength());
}

if (ATTRIBUTE8.length > ATTRIBUTE8.getLength())
{
ATTRIBUTE8 = ATTRIBUTE8.substr(0,ATTRIBUTE8.getLength());
}

if (ATTRIBUTE9.length > ATTRIBUTE9.getLength())
{
ATTRIBUTE9 = ATTRIBUTE9.substr(0,ATTRIBUTE9.getLength());
}

if (ATTRIBUTE10.length > ATTRIBUTE10.getLength())
{
ATTRIBUTE10 = ATTRIBUTE10.substr(0,ATTRIBUTE10.getLength());
}

if (ATTRIBUTE11.length > ATTRIBUTE11.getLength())
{
ATTRIBUTE11 = ATTRIBUTE11.substr(0,ATTRIBUTE11.getLength());
}

if (ATTRIBUTE12.length > ATTRIBUTE12.getLength())
{
ATTRIBUTE13 = ATTRIBUTE12.substr(0,ATTRIBUTE12.getLength());
}

if (ATTRIBUTE13.length > ATTRIBUTE13.getLength())
{
ATTRIBUTE13 = ATTRIBUTE13.substr(0,ATTRIBUTE13.getLength());
}

if (ATTRIBUTE14.length > ATTRIBUTE14.getLength())
{
ATTRIBUTE14 = ATTRIBUTE14.substr(0,ATTRIBUTE14.getLength());
}

if (ATTRIBUTE15.length > ATTRIBUTE15.getLength())
{
ATTRIBUTE15 = ATTRIBUTE15.substr(0,ATTRIBUTE15.getLength());
}

if (ATTRIBUTE16.length > ATTRIBUTE16.getLength())
{
ATTRIBUTE16 = ATTRIBUTE16.substr(0,ATTRIBUTE16.getLength());
}

if (ATTRIBUTE17.length > ATTRIBUTE17.getLength())
{
ATTRIBUTE17 = ATTRIBUTE17.substr(0,ATTRIBUTE17.getLength());
}

if (ATTRIBUTE18.length > ATTRIBUTE18.getLength())
{
ATTRIBUTE18 = ATTRIBUTE18.substr(0,ATTRIBUTE18.getLength());
}

if (ATTRIBUTE19.length > ATTRIBUTE19.getLength())
{
ATTRIBUTE19 = ATTRIBUTE19.substr(0,ATTRIBUTE19.getLength());
}

if (ATTRIBUTE20.length > ATTRIBUTE20.getLength())
{
ATTRIBUTE20 = ATTRIBUTE20.substr(0,ATTRIBUTE20.getLength());
}

MattCasters
04-20-2006, 11:14 PM
Hi,



<pre>
A.substr(0, A.getLength() );
</pre>
This seems to work fine for me. Doesn't give an error.

BTW, to get the length of the actual String, use the length() function.



HTH,

Matt