Since there came no answers, I started looking for the answers myself. And eventualy I found the solution. It was a combination of Greg Collins http://www.infopathdev.com/files/folders/examples/entry283.aspx and Matt Faus http://www.infopathdev.com/blogs/matt/archive/2006/02/02/Setup-Namespaces-for-a-Secondary-Data-Source.aspx that did the job. I would like to thank both of you for the provided help. For what it's worth, this is the code
/*
* This file contains functions for data validation and form-level events.
* Because the functions are referenced in the form definition (.xsf) file,
* it is recommended that you do not modify the name of the function,
* or the name and number of arguments.
*
*/
// The following line is created by Microsoft Office InfoPath to define the prefixes
// for all the known namespaces in the main XML data file.
// Any modification to the form files made outside of InfoPath
// will not be automatically updated.
// Added namespace according to Matt's article
//<namespacesDefinition>
XDocument.DOM.setProperty("SelectionNamespaces",'xmlns:q="http://schemas.microsoft.com/office/infopath/2003/ado/queryFields" xmlns:d="http://schemas.microsoft.com/office/infopath/2003/ado/dataFields" xmlns:dfs="http://schemas.microsoft.com/office/infopath/2003/dataFormSolution" xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2007-06-19T11:16:40"');
XDocument.GetDOM("Approvers").setProperty("SelectionNamespaces",'xmlns:ns1="http://schemas.microsoft.com/office/infopath/2003/dataFormSolution" xmlns:d1="http://schemas.microsoft.com/office/infopath/2003/ado/dataFields"')
//</namespacesDefinition>
// This function is added out of Greg's example
// To tell the truth: I don't really know where this is about.
// String object extension. Usage: stringObj.FunctionName([parameters]);
// Example usage: "This is a {0}".Format("test."); returns "This is a test.";
String.prototype.Format = new Function("var arg = String.prototype.Format.arguments; var str=this.toString(); var ph,re; for(var i=0;i<arg.length;i++){ph=new RegExp('\{('+i+')\}','ig'); if(null==arg[i]) re=''; else re=arg[i].toString(); str=str.replace(ph,re);} return str;");
//=======
// The following function handler is created by Microsoft Office InfoPath.
// Do not modify the name of the function, or the name and number of arguments.
// This function is associated with the following field or group (XPath): /dfs:myFields/my:Department
// Note: Information in this comment is not updated after the function handler is created.
//=======
function msoxd_my_Department::OnAfterChange(eventObj)
{
// Write code here to restore the global state.
if (eventObj.IsUndoRedo)
{
// An undo or redo operation has occurred and the DOM is read-only.
return;
}
// Retrieve department info into sSearchstring
var sSearchString = trim(XDocument.DOM.text);
// setup connection for EmployeeInfo
var oAdoAdapter = XDocument.DataObjects("EmployeeInfo").QueryAdapter;
// construct select
var sCommand = "select EmployeeID, Lastname + ' ' +Firstname + ' (' + EmployeeID + ')' as employeeinfo,orgunitdescr from dbo.EMPLOYEE where OrgUnitDescr = '" + sSearchString +"' and plantaa='AA' order by employeeinfo";
// apply appropriate select
oAdoAdapter.Command = sCommand;
// Requery the datasource
oAdoAdapter.Query();
// XDocument.UI.Alert("Please stop")
}
function trim(string) {
// retourneert de getrimde string (string ontdaan van leading en trailing whitespaces/tabs/newlines)
var remove = " \t\r\n"; // te verwijderen karakters
var ret = ""; // return string
var start = 0; // startpositie in de te controleren string
var end = string.length - 1; // eindpositie in de te controleren string
// schuif de startpositie op
while(start <= end && remove.indexOf(string.charAt(start)) != -1) {
start++;
}
// schuif de eindpositie op
while(end >= start && remove.indexOf(string.charAt(end)) != -1) {
end--;
}
// als string leeg is, geldt (end + 1 == start)
// bouw de overgebleven string
for(i=start; i <= end; i++) {
ret += string.charAt(i);
}
return ret;
}
//=======
// The following function handler is created by Microsoft Office InfoPath.
// Do not modify the name of the function, or the name and number of arguments.
// This function is associated with the following field or group (XPath): /dfs:myFields/dfs:dataFields/d:LOCALSALES/@Approved_by1
// Note: Information in this comment is not updated after the function handler is created.
//=======
function msoxd__LOCALSALES_Approved_by1_attr::OnAfterChange(eventObj)
{
// Retrieve department info into sSearchstring
// I suppose eventObj.NewValue gets the information just entered.
var sName = eventObj.NewValue;
// Another 2 lines that are a mistery to me
var oRow = eventObj.Site.selectSingleNode("..");
var oSqlCustomer = XDocument.GetDOM("Approvers").selectSingleNode("//d1:LOCALSALES_APPROVERS[@EmployeeID = '{0}']".Format(sName));
var sSearchString = oSqlCustomer.getAttribute("EmployeeEmail")
// But the correct information shows up
XDocument.UI.Alert(sSearchString)
if (eventObj.IsUndoRedo)
{
// An undo or redo operation has occurred and the DOM is read-only.
return;
}
}
Also thanks to davidair for the initial answers.
Hans.
Infopath 2003 / Jscript