I appologize for the redundancy, but I'm experiencing a similar issue and can't figure out what I'm doing wrong. Basically, I have a "Status" field and when it changes, I want to append to the history that the Status has changed...the history is appending twice and am not sure how to have it append once...any help would be greatly appreciated...
Thanks
Thomas N Barrett
function msoxd_my_Approval_Status::OnAfterChange(eventObj)
{
// Write code here to restore the global state.
if (!eventObj.IsUndoRedo && eventObj.Operation == "Delete"
&& eventObj.Site.nodeName == "item" &&
eventObj.Source.nodeName == "item")
{
return;
}
var StatusChoice = XDocument.DOM.selectSingleNode("/my:myFields/my:InputData/my:Approval_Status").text
switch (StatusChoice)
{
case "Approved":
XDocument.DOM.selectSingleNode("/my:myFields/my:Admin/my:Approval_Status_FLAG").text = "Approved";
XDocument.DOM.selectSingleNode("/my:myFields/my:Admin/my:Approval_Status_Change_Date").text = todaysDate();
// Append to History that the Current Status has changed...Also, capture Username and Date / Time stamp of the Current Status change
var CurrentUser = XDocument.DOM.selectSingleNode("/my:myFields/my:Admin/my:AdminSection/my:Current_User_Name").text;
var newComment = XDocument.DOM.selectSingleNode("/my:myFields/my:NewCommentGroup/my:NewComment").text;
// Create the individual nodes (for the Comment History Table)
var nodeCommentHistoryTableRows = XDocument.DOM.createNode(1, "CommentHistoryTable", "http://schemas.microsoft.com/office/infopath/2003/myXSD/2007-03-16T18:51:51");
var nodeCommentUserName = XDocument.DOM.createNode(1, "CommentUserName", "http://schemas.microsoft.com/office/infopath/2003/myXSD/2007-03-16T18:51:51");
var nodeCommentDate = XDocument.DOM.createNode(1, "CommentDate", "http://schemas.microsoft.com/office/infopath/2003/myXSD/2007-03-16T18:51:51");
var nodeCommentHistory = XDocument.DOM.createNode(1, "CommentHistory", "http://schemas.microsoft.com/office/infopath/2003/myXSD/2007-03-16T18:51:51");
// Create the node structure for the Comment History Table
nodeCommentHistoryTableRows.appendChild(nodeCommentUserName);
nodeCommentHistoryTableRows.appendChild(nodeCommentDate);
nodeCommentHistoryTableRows.appendChild(nodeCommentHistory);
// Append Values
nodeCommentUserName.text = CurrentUser;
nodeCommentDate.text = XDocument.DOM.selectSingleNode("/my:myFields/my:Admin/my:Approval_Status_Change_Date").text;
nodeCommentHistory.text = "Current Status changed to: " + XDocument.DOM.selectSingleNode("/my:myFields/my:Admin/my:Approval_Status_FLAG").text;
// Append row to XML document
var parent = XDocument.DOM.selectSingleNode("/my:myFields/my:CommentHistoryGroup");
parent.appendChild(nodeCommentHistoryTableRows);
break;
case "In Process":
XDocument.DOM.selectSingleNode("/my:myFields/my:Admin/my:Approval_Status_FLAG").text = "In Process";
XDocument.DOM.selectSingleNode("/my:myFields/my:Admin/my:Approval_Status_Change_Date").text = todaysDate();
// Append to History that the Current Status has changed...Also, capture Username and Date / Time stamp of the Current Status change
var CurrentUser = XDocument.DOM.selectSingleNode("/my:myFields/my:Admin/my:AdminSection/my:Current_User_Name").text;
var newComment = XDocument.DOM.selectSingleNode("/my:myFields/my:NewCommentGroup/my:NewComment").text;
// Create the individual nodes (for the Comment History Table)
var nodeCommentHistoryTableRows = XDocument.DOM.createNode(1, "CommentHistoryTable", "http://schemas.microsoft.com/office/infopath/2003/myXSD/2007-03-16T18:51:51");
var nodeCommentUserName = XDocument.DOM.createNode(1, "CommentUserName", "http://schemas.microsoft.com/office/infopath/2003/myXSD/2007-03-16T18:51:51");
var nodeCommentDate = XDocument.DOM.createNode(1, "CommentDate", "http://schemas.microsoft.com/office/infopath/2003/myXSD/2007-03-16T18:51:51");
var nodeCommentHistory = XDocument.DOM.createNode(1, "CommentHistory", "http://schemas.microsoft.com/office/infopath/2003/myXSD/2007-03-16T18:51:51");
// Create the node structure for the Comment History Table
nodeCommentHistoryTableRows.appendChild(nodeCommentUserName);
nodeCommentHistoryTableRows.appendChild(nodeCommentDate);
nodeCommentHistoryTableRows.appendChild(nodeCommentHistory);
// Append Values
nodeCommentUserName.text = CurrentUser;
nodeCommentDate.text = XDocument.DOM.selectSingleNode("/my:myFields/my:Admin/my:Approval_Status_Change_Date").text;
nodeCommentHistory.text = "Current Status changed to: " + XDocument.DOM.selectSingleNode("/my:myFields/my:Admin/my:Approval_Status_FLAG").text;
// Append row to XML document
var parent = XDocument.DOM.selectSingleNode("/my:myFields/my:CommentHistoryGroup");
parent.appendChild(nodeCommentHistoryTableRows);
break;
case "Rejected":
XDocument.DOM.selectSingleNode("/my:myFields/my:Admin/my:Approval_Status_FLAG").text = "Rejected";
XDocument.DOM.selectSingleNode("/my:myFields/my:Admin/my:Approval_Status_Change_Date").text = todaysDate();
// Append to History that the Current Status has changed...Also, capture Username and Date / Time stamp of the Current Status change
var CurrentUser = XDocument.DOM.selectSingleNode("/my:myFields/my:Admin/my:AdminSection/my:Current_User_Name").text;
var newComment = XDocument.DOM.selectSingleNode("/my:myFields/my:NewCommentGroup/my:NewComment").text;
// Create the individual nodes (for the Comment History Table)
var nodeCommentHistoryTableRows = XDocument.DOM.createNode(1, "CommentHistoryTable", "http://schemas.microsoft.com/office/infopath/2003/myXSD/2007-03-16T18:51:51");
var nodeCommentUserName = XDocument.DOM.createNode(1, "CommentUserName", "http://schemas.microsoft.com/office/infopath/2003/myXSD/2007-03-16T18:51:51");
var nodeCommentDate = XDocument.DOM.createNode(1, "CommentDate", "http://schemas.microsoft.com/office/infopath/2003/myXSD/2007-03-16T18:51:51");
var nodeCommentHistory = XDocument.DOM.createNode(1, "CommentHistory", "http://schemas.microsoft.com/office/infopath/2003/myXSD/2007-03-16T18:51:51");
// Create the node structure for the Comment History Table
nodeCommentHistoryTableRows.appendChild(nodeCommentUserName);
nodeCommentHistoryTableRows.appendChild(nodeCommentDate);
nodeCommentHistoryTableRows.appendChild(nodeCommentHistory);
// Append Values
nodeCommentUserName.text = CurrentUser;
nodeCommentDate.text = XDocument.DOM.selectSingleNode("/my:myFields/my:Admin/my:Approval_Status_Change_Date").text;
nodeCommentHistory.text = "Current Status changed to: " + XDocument.DOM.selectSingleNode("/my:myFields/my:Admin/my:Approval_Status_FLAG").text;
// Append row to XML document
var parent = XDocument.DOM.selectSingleNode("/my:myFields/my:CommentHistoryGroup");
parent.appendChild(nodeCommentHistoryTableRows);
break;
}
// A field change has occurred and the DOM is writable. Write code here to respond to the changes.
}
Thomas N. Barrett