I have a filtered list of items. The first row in the list has an itemNumber field with a value of 0 as applied on the template.xml.
I have a button to add a new item. When pressed the view is changed to an input form. On the input form I have a field newitemNumber.
I wish to take the value of the last itemNumber from the list, increment by 1 and apply this to the field newitemNumber. This will then provide a unique identifier for when the save button creates a new item and adds to the list.
My code follows, guess what...it doesn't work. The list is empty, new item button is actioned and the input form has unique value of 1, which is to be expected. When the button is actioned another time, the value stays at 1 instead of incrementing by 1.
I feel sure using the LastNode property would be a better approach but I haven't got that far yet. any help would be appreciated.
var itemList = XDocument.DOM.selectNodes( "/my:Fields/my:RoomData/my:RoomDetail" );
var iNumber = 0;
while( row = itemList.nextNode() )
{
var getUniqueID = getNodeTypedValue(row.selectSingleNode( "my:itemNumber" ));
iNumber += getUniqueID
}
var UniqueID = iNumber + 1;
XDocument.View.SwitchView("Input Form");
XDocument.DOM.selectSingleNode("//my:newItemNumber").text = UniqueID;
Regards Spudy