I am trying to populate an XML field when a process instance is created from a web page and I'm getting the following error:
System.Xml.XmlException: Root element is missing. at System.Xml.XmlTextReaderImpl.Throw(Exception e) at System.Xml.XmlTextReaderImpl.ThrowWithoutLineInfo(String res) at System.Xml.XmlTextReaderImpl.ParseDocumentContent() at System.Xml.XmlTextReaderImpl.Read() at System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader, Boolean preserveWhitespace) at System.Xml.XmlDocument.Load(XmlReader reader) at System.Xml.XmlDocument.LoadXml(String xml) at FixSchedulingLink.CreateProcessInstance(String k2ServerName, String ProcessName, String ProjectName) in c:inetpubwwwrootSOAFixSchedulingLink.aspx.cs:line 655
I am recreating this workflow in Blackpearl and trying to use the same code I used in K2.net 2003. My code is as follows:
protected void CreateProcessInstance(string k2ServerName, string ProcessName, string
ProjectName)
{
// Instantiate connection object
SourceCode.K2ROM.
Connection myConn = new SourceCode.K2ROM.Connection
();
SourceCode.K2ROM.
ProcessInstance
myProc;
string process = (ProjectName) + @"" + "Scheduling";
//(ProcessName);
try
{
myConn.Open(k2ServerName);
myProc = myConn.CreateProcessInstance(process);
//Populate DataFields
myProc.DataFields[
"MoogPartNumber"
].Value = txtMoogPN.Text;
myProc.DataFields[
"ItemCode"
].Value = txttcitg.Text;
myProc.DataFields[
"ItemCodeDesc"
].Value = txttdsca.Text;
myProc.DataFields[
"CustomerPartNumber"
].Value = txtCustomerPNTruncateRev.Text;
myProc.DataFields[
"ItemCodeFirst"
].Value = lsttcitg.Items[0].ToString();
myProc.DataFields[
"ADDepartment"
].Value = txtDepartment.Text;
myProc.DataFields[
"ADFullName"
].Value = txtFullName.Text;
myProc.DataFields[
"ADLoginName"
].Value = txtLoginName.Text;
myProc.DataFields[
"CustName"].Value = this
.lblCustomerName.Text.Trim();
myProc.DataFields[
"BaaNID"].Value = this
.lblBaaNId.Text;
myProc.DataFields[
"SOAAction"].Value = "FixSchedLink"
;
myProc.DataFields[
"SalesOrderNum"].Value = this
.txtSalesOrderNum.Text;
myProc.DataFields[
"Site"].Value = "Blacksburg"
;
myProc.DataFields[
"SOAAction"].Value = "SchedLink"
;
////Populate XML fields
string XMLFieldName = "PartNumberList"
;
System.Xml.
XmlDocument
XMLDoc;
XMLDoc =
new XmlDocument
();
XMLDoc.LoadXml(myProc.XmlFields[XMLFieldName].MetaData);
//output lstdsca list items to lbldsca
int
i;
int
pn = lstMoogPN.Items.Count;
//int pnLess1 = pn - 1;
for
(i = 0; i < pn; i++)
{
XmlElement elePart = XMLDoc.CreateElement("Part"
);
XmlElement elePartNumber = XMLDoc.CreateElement("Number"
);
XmlElement eleItemCode = XMLDoc.CreateElement("ItemCode"
);
XmlElement eleItemCodeDesc = XMLDoc.CreateElement("ItemCodeDesc"
);
XmlElement eleCustomerPartNumber = XMLDoc.CreateElement("CustomerPartNumber"
);
elePartNumber.InnerText = lstMoogPN.Items.ToString();
XMLDoc.SelectSingleNode(
"Part/Number"
).AppendChild(elePartNumber);
eleItemCode.InnerText = lsttcitg.Items.ToString();
XMLDoc.SelectSingleNode(
"Part/ItemCode"
).AppendChild(eleItemCode);
eleItemCodeDesc.InnerText = lsttdsca.Items.ToString();
XMLDoc.SelectSingleNode(
"Part/ItemCodeDesc"
).AppendChild(eleItemCodeDesc);
eleCustomerPartNumber.InnerText = lstCustomerPNTruncateRev.Items.ToString();
XMLDoc.SelectSingleNode(
"Part/CustomerPartNumber"
).AppendChild(eleCustomerPartNumber);
}
myProc.XmlFields[XMLFieldName].Value = XMLDoc.InnerXml;
//set Process Folio
myProc.Folio =
"SOA " + "FixSchedLink "
+ lblSalesOrderNum.Text;
lblError.Text =
"Submitted."
;
//Start process instance
myConn.StartProcessInstance(myProc,
false
);
//myProc = myConn.StartProcessInstance(processName);
//Close connection
myConn.Close();
}
catch (Exception
ex)
{
lblError.Text =
"Error creating process instance: "
+ ex.ToString();
My XML field in the K2 development studio looks like the following:
Field Name: PartNumberList
Initial Value:
<Part xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ItemCode>ItemCode1</ItemCode>
<ItemCodeDesc>ItemCodeDesc1</ItemCodeDesc>
<Number>Number1</Number>
<CustomerPartNumber>CustomerPartNumber1</CustomerPartNumber>
</Part>
Doe anyone have any idea what I may be doing wrong here?
Thanks!
Holly Myers