Instantiating the process


Badge +8

I created a windows application to instantiate a process instance using the following code.. but i got the following error 'Data at root level is invalid Line 1; Position 1' in the workspace


 


Connection K2Con = new Connection();


K2Con.Open("ServerName:Port");


ProcessInstance processinstance = K2Con.CreateProcessInstance(@"ProjectProcess");


processinstance.Folio = "folio";


XmlDocument xmltemplate = new XmlDocument();


xmltemplate.Load("G:sample.xml");


processinstance.XmlFields["Template"].Value = xmltemplate.ToString();


K2Con.StartProcessInstance(processinstance);


 processinstance.Update();


K2Con.Close();


 


 


http://www.k2underground.com/forums/thread/18894.aspx was my reference..


 


Have i done anything wrong??


 


8 replies

Badge +4

They syntax looks correct. So the issue might be in the logic  :) -  (You  dont need that processinstance.update();  call at the end for the purpose of this exercise )

I would check the contents of the xml file you are setting and ensure that it is valid for the schema of the XmlField.


Badge +8

Instead of kicking off a process by submitting the infopath form i wanted to instate a process with a default template. So i previewed the form in infopath client and set the field values and saved the file in my computer. So that this would become a standard template for the process to ahead.

Badge +6

not sure this will help.


Jey is right, you don't need to update() your processinstance object, because the StartProcessInstance method perform the update of the XMLFields and DataFields you've just set.


If you need to do an update... you need to have some specific process rights (admin).


When you set your XmlField.. have you ever try this:


processinstance.XmlFields["Template"].Value = xmltemplate.InnerXml();


or


processinstance.XmlFields["Template"].Value = xmltemplate.InnerText();


HTH

Badge +8

Im updating because i need to send mails which gets to address from the infopath. thats wy..


Anyways ill try ur code and let u know


 

Badge +9

To Jan's point about not needing to call the Update() method...

Update() is only invoked when data and/or XML fields are being updated without the need to trigger process execution.  For example, if you have an active instance and simply need to update data field values, but not move the process to its next state.  Update() is not used when invoking StartProcessInstance() or Action.Execute() as the datafields will be updated automatically (assuming they were changed before the Start/Execute call) as a result.

 

Badge +8

Thanks for clarifying bob, But wouldn i need to do the update if im invoking a process tied to a infopath template.?? Because the mail activity has look up to the infopath datasource in its config(for ex: the to addresses)


And Jan,


The code is working fine now

Badge +9
No, if you are calling StartProcessInstance or Action.Execute you do not need to explicitly invoke Update().  StartProcessInstance and Action.Execute basically automatically invokes an Update for you, then instructs K2 to execute the workflow logic after the updating.  Update() is used to simply save data back to the process instance and does not trigger any workflow execution (e.g. Lines are not followed, events are not finished...)
Badge +8
Ok Bob, thanks

Reply