Two Infopath Forms in one Process

  • 4 March 2008
  • 8 replies
  • 0 views

Badge +8

Hi,


I want to use to Infopath forms in one process. I think this should be possible. The problem is that I want to display fields and values form Infopath form1 in the Infopath form2. Is this possible in the process by using events?


Jochen


8 replies

Badge +5

Can you describe more of the actual process you are trying to accomplish. 

Badge +9
Yes, it is absolutely possible.  I will give you a vague answer here, if you need more specifics I can provide them though there are a couple of other topics out here around this.  When you integrate InfoPath forms in your process, it automatically creates XML fields that represent each form.  In server code, you can access these XML fields and set values any way you see fit.  So after the user fills out form 1, you can have a server code event set fields in form 2 equal to their corrisponding values in form 1.  Hope this puts you on the right track.
Badge +8

I have written server events events to get some data from the xml fields. but I don't know how to set the xml fields of the second infopath form.


Here is a little Code exemple I have done yet:


XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(K2.ProcessInstance.XmlFields["test"].Value.ToString());


XmlNamespaceManager nsMgr = new XmlNamespaceManager(xmlDoc.NameTable);
nsMgr.AddNamespace("my", xmlDoc.DocumentElement.GetNamespaceOfPrefix("my"));
string approver2 = xmlDoc.SelectSingleNode("//my:myFields/my:approver2", nsMgr).InnerText;

Badge +8

Probably with this statement I will be able to set a XML value


xmlDoc.SelectSingleNode("//my:myFields/my:approver2", nsMgr).Value = "text"


or is this too simple?

Badge +9

Little bit too simple, but almost there.  You need to put the updated xml back into your xml field, like this:


 K2. ProcessInstance.XmlFields["test"].value = xmlDoc.InnerXml

Badge +8

xmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(K2.ProcessInstance.XmlFields["test"].Value.ToString());
XmlNamespaceManager nsMgr = new XmlNamespaceManager(xmlDoc.NameTable);
nsMgr.AddNamespace("my", xmlDoc.DocumentElement.GetNamespaceOfPrefix("my"));


 xmlDoc.SelectSingleNode("//my:myFields/my:text2", nsMgr).Value = "text";
 K2.ProcessInstance.XmlFields["test"].Value = xmlDoc.InnerXml;


When I write this code I get the following error message


"Cannot set a value on node type 'Element'."


 any idea?
thx

Badge +8

Yes! You have to make a little change:


xmlDoc.SelectSingleNode("//my:myFields/my:text2", nsMgr).Value = "text";


should be


xmlDoc.SelectSingleNode("//my:myFields/my:text2", nsMgr).InnerText = "text";

Badge +8

yes. your are rigth.


Thank you!

Reply