I have a DataConnection that queries the UserProfile service from sharepoint, which I want to use to populate a field in my infopath form. I'm sure everyone here who has entertained such a need by now has seen a post similar to
this for a codeless solution and used it. When my form requirements were simple, that was perfect for my needs. As my form has grown more complex, I need to see if there's a way I can do this programmatically, because I need to create form load conditions to switch views based on the status of the form and who loads it up, and to do so with rules would be VERY cumbersome due to the various conditions. I would keep the rule to retrieve the username value at loading, and then use code based off of that, but unfortunately in the browser the code runs first for loading, then the loading rules are ran next, so I wouldn't have a value in my "CurrentUser" field, so... I'm out of luck there.
Playing around with the code, I've done this so far, which admittedly isn't much:
DataSource userName = this.DataSources["GetUserProfileByName"];
XPathNavigator MainDS = MainDataSource.CreateNavigator();
XPathNavigator SetValue = MainDS.SelectSingleNode("/my:myFields/my:testest", NamespaceManager);
SetValue.SetValue(userName.CreateNavigator().InnerXml.ToString());
Using that, I can see the entire XML that is returned by the secondary data source. It is an incredibly long string, but I do see the PreferredName element in that ginormous string, and it contains the value I want. Does anyone know how I can parse this string and just retrieve the value of the preferredname element? Or, is there a better method of doing this programmatically that I'm unaware of? My searching for a solution on performing this seems to be everyone talking up their no code solution to this issue, or people talking about looping through a secondary data source to populate a repeating table.
For reference, I attached a text file with a portion of the xml string, so you can see what it looks like. I was going to put it in the post, but I couldn't figure out how to properly format the post with the xml in there. Thanks in advance for any help you may be able to offer here.