We have Infopath form which integrated with SmartObject. One of the SmartObject is:
AP_ProductListSO_GetProductList
This SmartObject will return list of all product. We use this SmartObject in our product search section in our infopath form shown below:
The search input fields were bind to the following “Main” data source:
Product Name = PDS_ByProductName
Product Number = PDS_ByProductNumber
The result fields were bind to the following “Secondary” data source (SmartObject):
Product Name = ProductDescription (AP_ProductListSO_GetProductList)
Product Number = ProductNumber (AP_ProductListSO_GetProductList)
Cost = StandardCost (AP_ProductListSO_GetProductList)
The Search Product button has the following rule configured to it:
The Add button has the following form code (managed code behind).
public void btn_Add_PDS_Clicked(object sender, ClickedEventArgs e)
{
// Write your code here.
// get the input values
string val1 = MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:ProductDetails_Search/my:PDS_gpProductResults/my:PDS_ProductName", NamespaceManager).Value;
string val2 = MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:ProductDetails_Search/my:PDS_gpProductResults/my:PDS_ProductNumber", NamespaceManager).Value;
string val3 = MainDataSource.CreateNavigator().SelectSingleNode("/my:myFields/my:ProductDetails_Search/my:PDS_gpProductResults/my:PDS_ProductStandardCost", NamespaceManager).Value;
// Add the product to the list
XmlDocument doc = new XmlDocument();
XmlNode group = doc.CreateElement("PDL_ProductResults2", NamespaceManager.LookupNamespace("my"));
XmlNode field = doc.CreateElement("PDL_ProductName2", NamespaceManager.LookupNamespace("my"));
XmlNode node = group.AppendChild(field);
node.InnerText = val1;
field = doc.CreateElement("PDL_ProductNumber2", NamespaceManager.LookupNamespace("my"));
node = group.AppendChild(field);
node.InnerText = val2;
field = doc.CreateElement("PDL_StandardCost2", NamespaceManager.LookupNamespace("my"));
node = group.AppendChild(field);
node.InnerText = val3;
field = doc.CreateElement("PDL_Quantity2", NamespaceManager.LookupNamespace("my"));
node = group.AppendChild(field);
node.InnerText = "1";
doc.AppendChild(group);
MainDataSource.CreateNavigator().SelectSingleNode(
"/my:myFields/my:ProductDetails_List2",
NamespaceManager).AppendChild(doc.DocumentElement.CreateNavigator());
}
This managed code is working when the value in PDS_ProductName, PDS_ProductNumber and PDS_StandardCost is manually type in and not from SmartObject return values.
When the add button is clicked it will add the line item into the Product List section.
However, we are unable to obtain the return values.
We have set the “AP_ProductListSO_GetProductList” SmartObject to return the value to the main data source by checking the “Add to Main DataSource” box:
Any feedback would be greatly appreciated as to how to obtain the return values from the SmartObject and insert to the Product List section using the above managed code.
Nb: I have attached doc with screenshot which missing from this post content.