Programatically update PO Lines, not flowing to PO header

I’m having some issues getting the PO amount from the lines to reflect properly on the PO header after changing the PO program.

I’m not doing anything particularly special. I’m manually updating the dataset values on the PODetail table, then calling the Update() function.

I’ve also tried updating the value on the header with the sum of all the lines, but even that doesn’t always reflect the correct value.

Is there a function in the Business object I’m supposed to call that updates the PO Header quantities for me? I was only able to find ChangeUnitPrice();

I need to be able to programatically update a PO line item, as a workaround for a business process.

Has anyone tried this? Am I missing something?

there are several ways of doing this but I’m going show you how to do it in UI - forms customization:

In the PO form customization go to Form Event Wizard under the Wizard tab.

  • Select Event Type: AfterAdapterMethod
  • under Adapters select - POAdapter
    -click arrow button to move it to Select New/Existing Eevnt Handler
  • click Update Event code button below

Update your code to the below:

//this code will get the PO Number and pass it to a procedure to calculate the total quantities of all the PODetail lines

private void oTrans_poAdapter_AfterAdapterMethod(object sender, AfterAdapterMethodArgs args)
{
// ** Argument Properties and Uses **
// ** args.MethodName **
// ** Add Event Handler Code **

	// ** Use MessageBox to find adapter method name
	// EpiMessageBox.Show(args.MethodName);
	switch (args.MethodName)
	{
		case "Update":
           
	         EpiDataView edv = oTrans.Factory("POHeader");
                    int PONum =  Convert.ToInt32(edv.dataView[edv.Row]["PONum"]);
                  CallPOAdapterGetDataMethod(PONum); 
			break;
	}

}

//Select Tools-Wizards-Customization Wizard-Business Logic Method Call to get POadaptor -GetData
private void CallPOAdapterGetDataMethod(int PONum)
{
try
{

		POAdapter adapterPO = new POAdapter(this.oTrans);
		adapterPO.BOConnect();

		int intId = PONum;
                   double TotalQty = 0.0;

		// Call Adapter method
		System.Data.DataSet dsPO = adapterPO.GetData(intId);
         
                if (dsPO != null)
		             {
		                 foreach (DataRow dr in dsPO.Tables["PODetail"].Rows)
				              {             
                               TotalQty = TotalQty +  Convert.ToDouble(dr["CalcOurQty"]);
                          }
                    }
      
            CallPOAdapterGetByIDMethod(PONum, TotalQty);
		// Cleanup Adapter Reference
		adapterPO.Dispose();

	} catch (System.Exception ex)
	{
		ExceptionBox.Show(ex);
	}
}

//Update POHeader field say Numeric10 fields with the total quanty

private void CallPOAdapterGetByIDMethod(int PONum, double TotalQty)
{
try
{

		POAdapter adapterPO = new POAdapter(this.oTrans);
		adapterPO.BOConnect();

		
		int intId = PONum;

		// Call Adapter method
		bool result = adapterPO.GetByID(intId);
            if (result)
           {
	    DataRow dr = adapterPO.POData.POHeader[adapterPO.POData.POHeader.Rows.Count - 1];
             
                 dr.BeginEdit();
                 dr["Number10"] =  TotalQty;
                 dr["RowMod"] = "U";
                 dr.EndEdit();
                 adapterPO.Update();
		      
         }
         oTrans.Refresh() ;

		// Cleanup Adapter Reference
		adapterPO.Dispose();

	} catch (System.Exception ex)
	{
		ExceptionBox.Show(ex);
	}
}

I don’t see anything particularly special about what you’re doing here. It looks like you’re just using the adapter to update the PO, after manually setting a value. That’s not quite the issue I’m having.

I’m starting off this way:

Erp.Proxy.BO.POImpl boPO = WCFServiceSupport.CreateImpl<Erp.Proxy.BO.POImpl>(session, ImplBase.UriPath);
PODataSet dsPO = boPO.GetByID(PONum);

for(int i = 0; i < dsPO.PODetail.Rows.Count; i ++)
{
dsPO.PODetail.Rows[i][“ScrUnitCost”] = unitPrice;
boPO.ChangeUnitPrice(dsPO);
orderTotal += unitPrice;
}
dsPO.POHeader.Rows[0][“TotalOrder”] = orderTotal;

boPO.Update(dsPO);

but for some reason this doesn’t seem to be updating the total header cost properly.