Cannot Populate Both PartNum and Cost at the Same Time on PODetail via UI Customization

Regarding the code below, specifically, this line:

edvPoDetail.dataView[edvPoDetail.Row]["PartNum"] = partNumValue; // Moved to first?

When this line is uncommented, the PartNum from SO populates on the PO, however, the previous line does not:

edvPoDetail.dataView[edvPoDetail.Row]["DocUnitCost"] = frCostValue;

However, when I comment out the “set PartNum line”, the DocUnitCost does populate.

If I uncomment PartNum, then DocUnitCost does not populate.

What’s going on? I’ve tried rearranging the order of the “set field” lines, but nothing makes a difference. If I set the PartNum, I cannot set the DocUnitPrice at the same time.

Bizarrely, all the other fields populate without an issue, including Quantity.

private void PODetail_AfterFieldChange(object sender, DataColumnChangeEventArgs args)
{
	switch (args.Column.ColumnName)
	{
		case "OrderNum_c":
			getComplianceDataFromSo();
			break;
		case "OrderLine_c":
			getComplianceDataFromSo();
			break;
	}
}

private void getComplianceDataFromSo()
{
	try
	{
		EpiDataView edvPoDetail = (EpiDataView)oTrans.EpiDataViews["PODetail"];
		
		// string orderLine = args.ProposedValue.ToString();
		string orderLine = edvPoDetail.dataView[edvPoDetail.Row]["OrderLine_c"].ToString();
		if(orderLine == "" || orderLine == "0") return;
		
		string orderNum = edvPoDetail.dataView[edvPoDetail.Row]["OrderNum_c"].ToString();
		if(orderNum == "" || orderNum == "0") return;

		// MessageBox.Show("Order Num: " + orderNum + "; Order Line: " + orderLine);

		DynamicQueryAdapter dqa = new DynamicQueryAdapter(oTrans);
		dqa.BOConnect();
		QueryExecutionDataSet qeds = dqa.GetQueryExecutionParametersByID("GetComplianceDataFromSo");
		qeds.ExecutionParameter.Clear();
		qeds.ExecutionParameter.AddExecutionParameterRow("OrderNum", orderNum, "nvarchar", false, Guid.NewGuid(), "A");
		qeds.ExecutionParameter.AddExecutionParameterRow("OrderLine", orderLine, "nvarchar", false, Guid.NewGuid(), "A");
		dqa.ExecuteByID("GetComplianceDataFromSo", qeds);

		string projectValue = "";  // Project_c
		string contractValue = ""; // Contract_C
		string inspectionValue = "";  // Inspection_c
		string urgencyValue = ""; // Urgency_c
		decimal frCostValue = 0; // Cost_c
		string partNumValue = ""; // PartNum
		decimal sellingQuantityValue = 0; // SellingQuantity
		string customerPriceValue = ""; // DocUnitPrice
		string dorValue = ""; // DOR_c

		if(dqa.QueryResults.Tables["Results"].Rows.Count > 0)
		{
			projectValue = (string)dqa.QueryResults.Tables[0].Rows[0][0];  // Project_c
			contractValue = (string)dqa.QueryResults.Tables[0].Rows[0][1]; // Contract_C
			inspectionValue = (string)dqa.QueryResults.Tables[0].Rows[0][2];  // Inspection_c
			urgencyValue = (string)dqa.QueryResults.Tables[0].Rows[0][3]; // Urgency_c
			if(contractValue.ToLower().Trim() == "no contract") contractValue = "";

			frCostValue = (decimal)dqa.QueryResults.Tables[0].Rows[0][4]; // Cost_c
			partNumValue = (string)dqa.QueryResults.Tables[0].Rows[0][5]; // PartNum
			sellingQuantityValue = (decimal)dqa.QueryResults.Tables[0].Rows[0][6]; // SellingQuantity
			// customerPriceValue = (string)dqa.QueryResults.Tables[0].Rows[0][7].ToString(); // DocUnitPrice
			dorValue = (string)dqa.QueryResults.Tables[0].Rows[0][8]; // DOR_c
		}
		edvPoDetail.dataView[edvPoDetail.Row]["Project_c"] = projectValue;
		edvPoDetail.dataView[edvPoDetail.Row]["Contract_c"] = contractValue;
		edvPoDetail.dataView[edvPoDetail.Row]["Inspection_c"] = inspectionValue;
		edvPoDetail.dataView[edvPoDetail.Row]["Urgency_c"] = urgencyValue;

		// MessageBox.Show("Order Num: " + orderNum + "; Order Line: " + orderLine + "; Project: " + projectValue + "; Contract: " + contractValue + "; Inspection: " + inspectionValue + "; Urgency: " + urgencyValue + "; FR Cost: " + frCostValue + "; Part Num: " + partNumValue + "; Quantity: " + sellingQuantityValue + "; Price: " + customerPriceValue + "; DOR: " + dorValue);

		edvPoDetail.dataView[edvPoDetail.Row]["DocUnitCost"] = frCostValue;
		edvPoDetail.dataView[edvPoDetail.Row]["PartNum"] = partNumValue; // Moved to first?
		edvPoDetail.dataView[edvPoDetail.Row]["CalcOurQty"] = sellingQuantityValue;
		// edvPoDetail.dataView[edvPoDetail.Row]["Urgency_c"] = customerPriceValue;
		// edvPoDetail.dataView[edvPoDetail.Row]["DOR_c"] = dorValue;

		// oTrans.Update();
		// oTrans.NotifyAll(true);
		// oTrans.Refresh();
	} catch(System.Exception ex) {
		ExceptionBox.Show(ex);
	}
}

Probably because the Cost updates automatically on change of part number. If you don’t have vendor price lists, it changes to zero.

1 Like

I would suggest that you do this with a BPM instead. Look for the Business Object that is called when you change the part number… in a POST PROCESSING BPM on that BO, do your lookup of the cost and populate it.

1 Like

I restructured it as:

edvPoDetail.dataView[edvPoDetail.Row]["PartNum"] = partNumValue;
oTrans.Update();
edvPoDetail.dataView[edvPoDetail.Row]["DocUnitCost"] = frCostValue;

Back in action, so far, so good. I appreciate the clues, thank you.