I am currently working on a project for my company and am building an Infopath 2003 document that needs to be accessible by many languages around the world. Taking a page from my web design thinking, I was working toward a solution where the translations for my Infopath document would be stored in a Sharepoint list, accessed through a data connection, and the matching values would be "mapped" to various expression boxes that look to the user to be Lables.
My Sharepoint translation list (ThirdPartyEvent_Translations) has the following attributes:
* stringid
* languageid
* translation
My language choice dropdown at the top of the page has each language and their matching id's (i.e. English/en, Spanish (Mexican)/es-sp).
So, here's what works right now:
* I have a language dropdown
* I have a Data connection to my sharepoint list that returns all my values
* I put an Expression box on my page and set it's value to a filtered result from the ThirdPartyEvent_Translations sharepoint data connection.
This was looking like it would take forever and there would be a lot of "hidden" code to manage. It seemed to me to be smarter to create a group in my data list called Labels. In that group I would have a list of all the StringIDs from my Sharepoint list and drag and drop those onto my form to serve as the labels for the form.
This is what I want to have happen:
Rather than hand-coding each box on the page, I want the value of each of the text boxes populated with the matching data from my Sharepoint List. Therefore, when a user first opens the form, I want the text boxes to all be populated with the selected value of the language dropdown and the matching language id. This is where I'm having my trouble. I've gone to the code-behind and played with some syntax, but it's clear I don't know what I'm doing! Here's what I have - and is not working. This is a specific example (trying to get the translation for one string id called "user_username"). I envision writing some type of script that would loop through each of the Sharepoint attributes and setting the corresponding Label value on the form. This would allow me to trigger the function either through the OnLoad event, or when the language drop down is changed. The UI.Alerts are there just for my testing, but in the real solution I would be setting the .text value to the matching text boxes on the page (something I can do and know the syntax for ).
function XDocument::OnLoad(eventObj)
{
var objTranslation = XDocument.DataObjects("ThirdPartyEvent_Translations").DOM;
objTranslation.setProperty("SelectionNamespaces",'xmlns:dfs="http://schemas.microsoft.com/office/infopath/2003/dataFormSolution" ' + ' xmlns:d="http://schemas.microsoft.com/office/infopath/2003/ado/dataFields"');
var selectedLanguage = XDocument.DOM.selectSingleNode("/my:myFields/my:languageview").text;
var selectedNode = objTranslation.selectSingleNode("//dfs:myFields/dfs:dataFields/d:ThirdPartyEvent_Translations[../@stringid='user_username' and ../@languageid='" + selectedLanguage + "']")
if (selectedNode.selectSingleNode("Translation").text == null)
{ XDocument.UI.Alert('nope'); }
else { XDocument.UI.Alert(selectedNode.selectSingleNode("Translation").text); }
}
This code results in a .js error "'null' is null or not an object" on the line "if (selectedNode.selectSingleNode("Translation").text == null) "
I would really appreciate it if someone could face me toward the light on this one!