How to access InfoPath field values in Default Server event code

  • 23 November 2009
  • 2 replies
  • 0 views

Badge +1

We are using InfoPath with K2 Blackpearl, once the approval are complete , we are writing our data into SQL database, but don't want to use smart objects, so we want to write the code in default server event (Code), but we are not able to access the InfoPath field values in C# code.


There is some K2.Processintsance.GetxmlVlaues.. method .. but its not working ...


Can anybody help me in that.


 


2 replies

Badge +2

I think this is covered in the blackpearl Wrox book but I don't have it in front of me to reference the page number but Jason Aperigis also has a really nice post on this as well here: http://www.k2distillery.com/2008/02/working-with-infopath-xml-and-archiving.html.


 


Hope this helps.

Badge +1

Thanks Jason,


I tired the same code earlier, but that time its works.. but this its seems to be working with some modification as i want to access the xml values not update..


Here is the modified code to access InfoPath field vales in code as XML


//Get the XML Field string
string xml = K2.ProcessInstance.XmlFields["XXX"].Value.ToString();

//Load up the XML
XmlDocument doc = new XmlDocument();
doc.LoadXml(xml);

//Create a name space manager for InfoPath
XmlNamespaceManager nsMgr = new XmlNamespaceManager(doc.NameTable);
nsMgr.AddNamespace("my", doc.DocumentElement.GetNamespaceOfPrefix("my"));

//Now set some values
fieldvalue  = doc.SelectSingleNode("//my:Company/my:CompanyID", nsMgr).InnerText;


Now you can use this field value to update the database by just writing a normal inline query.


Thanks again for your help .


Regards


Parveen


 

Reply