I know this has been asked and answered many times, but I'm still having trouble relating the solution it to my situation.
I have a Lookup field in a repeating table. When someone enters a value in the the field, it goes out to a 2nd data source and returns data. I want the record in the table to be filled with these returned fields. However when I set the fields, it's always the first record that gets filled, not the current record.
I came across Current() in this forum that seems to be the answer. I just don't know where it goes in my code. Can someone help me out?
Here is the code in the OnAfterChange event of the lookup field in the table record. I believe the Red lines are the ones that need to be changed.
Thanks
var node = XDocument.DOM.selectSingleNode("//dfs:myFields/dfs:dataFields/d:VendorSelect/@quotenum");
quote = node.text;
var obj = XDocument.DataObjects("VendorList");
obj.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/2005-12-26T21:32:32"');
var r = eventObj.NewValue;
obj.QueryAdapter.Command = "select * from VendorList where number = '" + r + "'";
obj.QueryAdapter.Query();
var node = obj.DOM.selectSingleNode("//dfs:myFields/dfs:dataFields/d:VendorList/@name");
if (node) {
var name = node.text;
var add = obj.DOM.selectSingleNode("//dfs:myFields/dfs:dataFields/d:VendorList/@address").text;
var city = obj.DOM.selectSingleNode("//dfs:myFields/dfs:dataFields/d:VendorList/@city").text;
var st = obj.DOM.selectSingleNode("//dfs:myFields/dfs:dataFields/d:VendorList/@state").text;
var zip = obj.DOM.selectSingleNode("//dfs:myFields/dfs:dataFields/d:VendorList/@zip").text;
var con = obj.DOM.selectSingleNode("//dfs:myFields/dfs:dataFields/d:VendorList/@contactname").text;
var num = obj.DOM.selectSingleNode("//dfs:myFields/dfs:dataFields/d:VendorList/@contactnum").text;
// var ema = obj.DOM.selectSingleNode("//dfs:myFields/dfs:dataFields/d:VendorList/@email").text;
}else {
var name = "";
var add = "";
var city = "";
var st = "";
var zip = "";
var con = "";
var num = "";
// var ema = "";
}
XDocument.DOM.selectSingleNode("//dfs:myFields/dfs:dataFields/d:VendorSelect/@quotenum").text = quote;
XDocument.DOM.selectSingleNode("//dfs:myFields/dfs:dataFields/d:VendorSelect/@name").text = name;
XDocument.DOM.selectSingleNode("//dfs:myFields/dfs:dataFields/d:VendorSelect/@address").text = add;
XDocument.DOM.selectSingleNode("//dfs:myFields/dfs:dataFields/d:VendorSelect/@city").text = city;
XDocument.DOM.selectSingleNode("//dfs:myFields/dfs:dataFields/d:VendorSelect/@state").text = st;
XDocument.DOM.selectSingleNode("//dfs:myFields/dfs:dataFields/d:VendorSelect/@zip").text = zip;
XDocument.DOM.selectSingleNode("//dfs:myFields/dfs:dataFields/d:VendorSelect/@contactname").text = con;
XDocument.DOM.selectSingleNode("//dfs:myFields/dfs:dataFields/d:VendorSelect/@contactnum").text = num;
//XDocument.DOM.selectSingleNode("//dfs:myFields/dfs:dataFields/d:VendorSelect/@email").text = ema;