cancel
Showing results for 
Search instead for 
Did you mean: 

Access a value attribute under a value node

Former Member
0 Kudos

Hi guys,

Could you please help me on this one. I need to access value attributes that are under a value node?. I use the following codes and I always have the error "java.lang.NullPointerException ".

1) wdThis.wdGetContext().currentMyValueNodeElement().getMyAttribute();

2) wdContext.currentMyValueNodeElement().getMyAttribute();

Thanks in advance

Franck

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

Have you initialised the node before you try to access the attribute?

If the cardinality of the node is 0..1 or 0..n then you have to manualy initialise it. If the cardinality is 1..1 or 1..n then you shouldn't get the null pointer exception.

Check that and get back to us.

Patrick.

Former Member
0 Kudos

Thanks a lot Patrick. It solved the problem. Cardinality of the node value was 0..n. I've changed it to 1..1 and now everything is ok.

Franck

Former Member
0 Kudos

Hi Franck, I'm glad to help.

Make sure that the cardinality of 1..1 is correct for your use case though. This cardinality means that only one 'instance' of your attribute can exist for the node. For instance, if you were going to display a table from that node then with a cardinality of 1..1 your table would have 1 and only 1 row.

Patrick.

Answers (1)

Answers (1)

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

HEre is an example where I'm pulling a value from a value attribute where the Node is a table. "Ytdsl" is the actual value attribute name.




		//      Get the total  from the last line of the table
		String sx =
			wdContext
				.nodeChannelList()
				.getElementAt((wdContext.nodeChannelList().size() - 1))
				.getAttributeValue("Ytdsl")
				.toString();

Regards,

Rich Heilman