Dependent Foreign Key View Iteration

Hi All,

I am trying to spool through shipment details and do some math on the foreign key view related to the shipment record. All of the shipment detail values work fine but my FKV value only returns the first record values during all of my iterations. See bolded line.

foreach(DataRowView rowView in edvShipDtl.dataView)
{
if((string)edvOrderDtl_FKV.dataView[edvOrderDtl_FKV.Row][0][“SalesCatID”] == “UPSR”)
{
extraCharge= extraCharge + (((decimal)rowView[“SellingInventoryShipQty”] * (decimal)edvOrderDtl_FKV.dataView[0][“DocUnitPrice”]) * .025M);

}
}

When I create a grid and tie the FKV to it and select the different shipment lines, it is shows the correct data but the code isn’t changing the order detail lines.

What am doing wrong or what is required to make the order detail FKV to change with my foreach loop? I suppose I could just retrieve the ending value from a BAQ but thought this approach would keep it in the module.

I realize that the % based misc charges are supposed to to this but there is a bug that only charges it on the first line when it is pulled into the invoice, so I have to create a workaround.

Thank you!
Ross

A FKV will only show you the current record’s information. There are a number of ways of doing what you show though. I would start with the simplest and use the wizard to create a Simple Search (Tools > Wizards > Customization Wizards > Simple Search). Get the OrderDtlSearchAdapter and it will provide options. Select the Search Dialog and the select your DocUnitPrice from the Search Field and bind it to any table/field as we will delete that part of the code.
After some changes to the code to make it work for us:

private decimal GetUnitPrice(int orderNum, orderLine)
{
	// Wizard Generated Search Method
	// You will need to call this method from another method in custom code
	// For example, [Form]_Load or [Button]_Click
		bool recSelected;
	string whereClause = String.Format("OrderNum = {0} and OrderLine = {1} and SalesCatID = 'UPSR'", orderNum, orderLine);
	System.Data.DataSet dsOrderDtlSearchAdapter = Ice.UI.FormFunctions.SearchFunctions.listLookup(this.oTrans, "OrderDtlSearchAdapter", out recSelected, false, whereClause);
	if (recSelected)
	{
		System.Data.DataRow adapterRow = dsOrderDtlSearchAdapter.Tables[0].Rows[0];
		return (decimal)adapterRow["DocUnitPrice"];
	}
	return 0;
}

To use it:

//Call the function
foreach(DataRowView rowView in edvShipDtl.dataView)
{
	decimal unitPrice = GetUnitPrice((int)rowView["OrderNum"], (int)rowView["OrderLine"]);
	if (unitPrice > 0)
	{
		extraCharge += (decimal)rowView["SellingInventoryShipQty"] * unitPrice * .025M;
	}
}
2 Likes

Excellent! Thanks, Jason. It works great and thanks for cluing me in to the FKV behavior in code.

Greatly appreciate it.

Regards,
Ross