Wednesday 11 April 2007

dynamic data using XPath functions for your InfoPath 2007 form elements

As MS advertises VSTO(Visual Studio Tools for Office) and its little bro VSTA(VST for Application) which is the conversion of VBA into vb.net/c# solution(which is good, I personally dislike VBA :p), InfoPath form can be developed by accessing form data dynamically using XPath.XPathNavigator such as following :


XML.XPath.XPathNavigator root,myField;
root = this.MainDataSource.CreateNavigator();
myField = root.SelectSingleNode("//my:myField",this.NamespaceManager);




then you can using myField.SetValue() /myField.Value to set/get the value of your textbox, dropdownlist and more...

In here, I want to introduce an interesting use of XPath functions built in to InfoPath. It's a scenario that you want to use a hyperlink to call out an email client installed on your local machine and fill out the form data on the client,say Outlook to prepare an email for your disposal in which case, VSTA/VSTO might be a bad/harder solution to implement(you don't get the address your hyperlink is pointing to since your hyperlink doesn't appear to be a xml node not in xml file at all...)

we all know that the RFC standard URL mailto: will get you the client :e.g. Outlook Express or Outlook for you with the subject, cc or whatever you append in the mailto string. But in InfoPath form, after you inserted a hyperlink and try to call out an email client, you might wonder how on earth you gonna have to type in this url in the text box, and the fatal shortcoming for this is that you don't get dynamic datafrom your form. Well, it's easy, using XPath fn : concat(string, string, my:myfield) in your data source field in the hyperlink property box. so you can use both static and dynamic data this way. see illustration


Hope this will save someone's time.Enjoy!

No comments: