Deborah Miller
Deborah Miller

Reputation: 1

SSJS - Error When Accessing Date Field

In SSJS I'm using doc.getDocument().getItemValue(dateFld)[0] to access the date field value.

For one and only one particular document, I'm getting "Error while accessing indexed property #'0' on ojbect class java.util.Vecotr Array index out of range: 0

I checked the field on that document and it has a date-time value; the format is no different from the documents that are working correctly. I even ran SSJS code that did a typeof on the field value and measured its size: it's a vector and its size is 1.

I've tried resetting the field value on the document. I've tried removing the field, then resetting it, to no avail.

This is the second time I've come across this problem concerning a date field. Anyone have any suggestions?

Upvotes: 0

Views: 120

Answers (2)

Fredrik Norling
Fredrik Norling

Reputation: 3484

I would add the following around your code, to assign a default value if the date field doesn't exits

if(doc.getDocument().hasItem(dateFld)){
//You code when the document exists

}else{
//Assign default value

}

Upvotes: 2

Oliver Busse
Oliver Busse

Reputation: 3395

You are getting this error because the item isn't in the backend document. Try using

doc.getDocument().getItemValueString("...")

or any other method that will return a "real" value instead of the Vector crap.

BTW: Don't use the [x] style to access the Vectored value - use .elementAt(x) instead when using the Vector returning methods :-)

Upvotes: 3

Related Questions