cancel
Showing results for 
Search instead for 
Did you mean: 

Adding elements to node

former_member540174
Participant
0 Kudos

I have a context node that contains 0..n items (AttendanceNode). This node contains daily attendance records for employees. I need to look at this node and add an element for any missing work days for each employee (thus each employee has at least one record for each work day).

I am looping though the attendance node in my context. What my question is - is it possible to create a temporary node that I put each of the elements in the attendance node plus the new ones I add - then copy the node back? Is there a better way to do this? My assumption is that it is not correct to add elements to a node you are looping though while you are in the loop.

Regards,

Diane

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi Diane,

If my understanding is correct, your requirement is as follows:

You have a node called AttendanceNode. It contains some elements, where each element represents attendance of one employee for one particular day. You want to loop through the node and add new elements for the missing dates.

Solution:

-> Loop through the Attendance node and note down the missing dates in one hash map.

-> Now loop throught the hashmap and create new elements with the missing dates and add it to the AttendanceNode.

(or)

-> Loop through the AttendanceNode and put the existing dates in hashmap.

-> Now loop through 1 to 30 or 31 based on the month, check if the date exists in hashmap or not using "if(!hm.contains(date))" and add the new element if necessary.

Note:This requires a logic to decide how many days you have to loop through. Whether it is 28 or 29 or 30 or 31 based on the month and year.

Regards,

VJR.

Former Member
0 Kudos

Hi,

I am not clear with your requirement , you can use the methods from WDCopyService to copy the contents of a node to other node

Ex: WDCopyService.copyElements(source, target)

Regards

Ayyapparaj

former_member540174
Participant
0 Kudos

I was just reading about the WDCopyService. Question...this target node - my assumption is I'll have to create another node in the context to be the target - do you have any sample code?

Former Member
0 Kudos

Hi,

yes you have to create another node with same attribute names like the source node (attendance).

(Armin: that's not correct, you don't need a node copy for inserting elements)

Regards,

ramesh

Edited by: Armin Reichert on Oct 14, 2008 4:51 PM

Former Member
0 Kudos

Hi,

I was just reading about the WDCopyService. Question...this target node - my assumption is I'll have to create another node in the context to be the target - do you have any sample code?

Yes you have to create the target node.

Ex :

Here Data and Table are two nodes where data is the source and table is the target.

WDCopyService.copyElements(wdContext.nodeData(), wdContext.nodeTable());

Regards

Ayyapparaj