You may consider using the simple approach of manipulating the structure of an XML datafield directly to achieve the objective.
For instance, if you have an XML field of the following structure that is bound to a K2DataGrid:
<K2DataGridRoot>
<Item>
<Comments></Comments>
<By></By>
<Date></Date>
</Item>
</K2DataGridRoot>
This K2DataGrid may be used to display comments from various people along the workflow. Use a server event that contains the following code at the end of each activity to update the XML by inserting a new row.
If K2.ProcessInstance.DataFields.Item("Comment").Value <> "" Then
Dim strItem As String = K2.ProcessInstance.XmlFields("ManagementComments").Value
strItem = strItem.Substring(0,strItem.IndexOf("</K2DataGridRoot>"))
strItem += "<Item><Comments>"+K2.ProcessInstance.DataFields.Item("Comment").Value + "</Comments>"
strItem += "<By>"+K2.ProcessInstance.DataFields.Item("ReviewedBy").Value + "</By>"
strItem += "<Date>"+K2.ProcessInstance.DataFields.Item("ReviewedDate").Value + "</Date></Item>"
strItem += "</K2DataGridRoot>"
K2.ProcessInstance.XmlFields("ManagementComments").Value = strItem
' clear comment field
K2.ProcessInstance.DataFields.Item("Comment").Value = ""
End if
Thanks Samuel,
I guess also you could load the field into the document model
System.Xml.XmlDocument myDocument = new System.Xml.XmlDocument();
myDocument.LoadXml(K2.ProcessInstance.XmlFields("ManagementComments").Value);
but, I like your method, and I hadn't thought about binding it to a datagrid which is excellent
Many thanks
To allow for multiple instances of an element (Comment in this case), as it is causing issues.
Am I better off storing my xml as a normal string Datafield, or is there a way to fix this to allow for multiple rows (I am gettingan xsdinfer.dll error on the page when I add a frid, due to the fact the schema does not by default allow you to configure multiple elements)