cancel
Showing results for 
Search instead for 
Did you mean: 

Scripting: Collection object members are null?

Former Member
0 Kudos

We are trying to validate the contents of a collection, and are having difficulty accessing individual members.

We have tried both using the iterator


Iterator iterator = collection.iterator();

while (iterator.hasNext()) {
 Object element = iterator.next();
 throw doc.createApplicationException("test",element);
}

And the .get() method of the collection variable that is supplied.


int i;

for (i=0;i<=collection.size();i++) {
  throw doc.createApplicationException("test",collection.get(i));
}

collection.size() shows that we have 2 members in the collection, but looping through them appears to return null objects.

Accepted Solutions (0)

Answers (3)

Answers (3)

0 Kudos

Hi All,

Did anyone find an answer to this?

Currently I am trying to access a member of  "Event specifications" or "QUESTION_LIST" collection

under SPEC tab in Rfx(RFP).

The problem is that even though the size of the collection is greater than 0 , I get NULL when i try to fetch any member of the same using get(index) method or iterator() method.

The code :-

f = doc.getCollectionMetadata("QUESTION_LIST").get(doc);

//f.get(0) returns null

//String s=f.get(0).getDisplayName(); throws error

Integer size=f.size();

throw doc.createApplicationException("",size.toString());//outputs 3

Thanks & Regards,

Mayank

Former Member
0 Kudos

Hi Sean, Martin,

In general, using the iterator or index will return the collection member.

However, I've noticed the problem you have described occuring with specific collections.

For example: RFx Response Line Items, Auction Vendors.

In both the cases, I could see the collection size returns a value > 0. But the individual collection members themselves could not be accessed.

Which collections were you trying to access?

Regards,

Reshma

Former Member
0 Kudos

Hi Sean,

First of all, tell me which language and tool u r using for ur coding ?

I used BeanShell Scripting and to print values of a collection is like

iterTest = testCollection.iterator()

for(member : iterTest){

fieldX = member.get(fieldX);

System.out.println("FieldX: "+fieldX);

}

Hope this will help you..

Himanshu Sharma

Former Member
0 Kudos

We are simply writing a collection validation script in the E-sourcing web interface, which use Beanshell. No tool per se.

I tried this syntax and I still get an error on the line


fieldX = member.get(fieldX);

internal Error: null variable value

The complete code is


iterTest = collection.iterator();

for(member : iterTest){
  fieldX = member.get(fieldX);
  System.out.println("FieldX: " + fieldX); 
}

collection.size is 2, so I know there's something in there.

martin_schffler
Participant
0 Kudos

Hello Sean,

we ran into the exact same problem. Did you find a solution to your problem?

Best regards,

Martin