While creating Purchase Order and multiple lines on button click using script editor system is throwing error “Invalid Sequence.” for your reference error and code is attached below
Haven’t done this with PO’s before, but aren’t you missing something after changing the unit price ? Mine calls ChangeUnitPriceConfirmOverride and ChangeUnitPrice. Maybe have a look at that ?
BPM runtime caught an unexpected exception of ‘NullReferenceException’ type.
See more info in the Inner Exception section of Exception Details.
Exception caught in: Epicor.ServiceModel
Error Detail
Description: BPM runtime caught an unexpected exception of ‘NullReferenceException’ type.
See more info in the Inner Exception section of Exception Details.
Program: ERP.PORel.Triggers.dll
Method: A001_CustomCodeAction
Original Exception Type: NullReferenceException
Client Stack Trace
at Epicor.ServiceModel.Channels.ImplBase`1.ShouldRethrowNonRetryableException(Exception ex, DataSet[] dataSets)
at Erp.Proxy.BO.POImpl.Update(PODataSet ds)
at Erp.Adapters.POAdapter.OnUpdate()
at Ice.Lib.Framework.EpiBaseAdapter.Update()
at Script.CallPOAdapterGetNewPOHeaderMethod(Int32 DMRNum, Int32 VendorNum, String VendorID, String BuyerID, String PartNum, Decimal DMRHead_TotRejectedQty, Decimal UnitPrice)
Inner Exception
Object reference not set to an instance of an object.
here is my code:
for currency currency, the CurrencySwitch property is False and for foreign currency it will be True, the default system is True
adapterPO.POData.Tables[“PODetail”].Rows[i][“CurrencySwitch”] = false;
private void CallPOAdapterGetNewPOHeaderMethod( int VendorNum, string VendorID, DataTable tblVenNumPOGen)
{
try
{
// Declare and Initialize EpiDataView Variables
// Declare and create an instance of the Adapter.
POAdapter adapterPO = new POAdapter(this.oTrans);
adapterPO.BOConnect();
// Call Adapter method
if(adapterPO.GetNewPOHeader())
{
adapterPO.POData.Tables["POHeader"].Rows[0]["VendorNum"] = VendorNum;
adapterPO.ChangeVendor(VendorID);
adapterPO.POData.Tables["POHeader"].Rows[0]["BuyerID"] = BuyerID;
adapterPO.Update();
}
//New PODetail
string sConfirmMsg = string.Empty, PartNum =string.Empty;
bool a = false, b = false;
int i=0, Line =1, DMRNum=0;
Guid sysRowID = new System.Guid("00000000-0000-0000-0000-000000000000");
int PONumNew = Int32.Parse(adapterPO.POData.Tables["POHeader"].Rows[0]["PONum"].ToString());
decimal DMRHead_TotRejectedQty=0, UnitPrice = 0;
//adapterPO.GetByID(PONumNew);
foreach (DataRow dtPOLine in tblVenNumPOGen.Rows)
{
DMRNum = Int32.Parse(dtPOLine["DMRHead_DMRNum"].ToString());
PartNum = dtPOLine["DMRHead_PartNum"].ToString();
DMRHead_TotRejectedQty = Convert.ToDecimal(dtPOLine["DMRHead_TotRejectedQty"].ToString());
UnitPrice = Convert.ToDecimal(dtPOLine["APInvDtl_UnitCost"].ToString());
if (adapterPO.GetNewPODetail(PONumNew))
{
adapterPO.POData.Tables["PODetail"].Rows[i]["POLine"]= Line;
adapterPO.ChangeDetailPartNum(ref PartNum, Guid.Parse(adapterPO.POData.Tables["PODetail"].Rows[i]["SysRowID"].ToString()), "", a, out b);
adapterPO.POData.Tables["PODetail"].Rows[i]["QtyOption"] = "Our";
adapterPO.POData.Tables["PODetail"].Rows[i]["DueDate"] = DateTime.Now.Date;
//adapterPO.POData.Tables["PODetail"].Rows[i]["OrderQty"] = DMRHead_TotRejectedQty;//Suppler Qty (VenQty)
//adapterPO.POData.Tables["PODetail"].Rows[i]["XOrderQty"] = DMRHead_TotRejectedQty;//Our Qty
adapterPO.ChangeDetailTranType("PUR-STK");
adapterPO.ChangeDetailCalcOurQty(DMRHead_TotRejectedQty);
//adapterPO.ChangeDetailCalcVendQty(DMRHead_TotRejectedQty);
if (UnitPrice ==0)
{
adapterPO.POData.Tables["PODetail"].Rows[i]["CheckBox02"] = true;//Gift
}
//set lại giá sau Qty để không bị lấy giá mặc trong PriceList
//nếu là tiền VND cần update lại không sẽ lấy giá về 0
if (adapterPO.POData.Tables["POHeader"].Rows[0]["CurrencyCode"].ToString()=="VND")
{
adapterPO.POData.Tables["PODetail"].Rows[i]["CurrencySwitch"] = false;
}
adapterPO.POData.Tables["PODetail"].Rows[i]["DocScrUnitCost"] = UnitPrice;
adapterPO.POData.Tables["PODetail"].Rows[i]["DocUnitCost"] = UnitPrice;//cột này là cột lưu đúng theo giá nếu là ngoại tệ sẽ là cột này
//adapterPO.POData.Tables["PODetail"].Rows[i]["DocExtCost"] = UnitPrice;
//adapterPO.POData.Tables["PODetail"].Rows[i]["UnitCost"] = UnitPrice;//cột này hệ thống sẽ tự quy đổi về tiền theo quốc gia của hệ thống ở VN là VND
adapterPO.ChangeUnitPriceConfirmOverride(out sConfirmMsg);
//adapterPO.ChangeUnitPrice();
adapterPO.POData.Tables["PODetail"].Rows[i]["RowMod"] = "A";
adapterPO.Update();
adapterPO.POData.Tables["PORel"].Rows[i]["Number02"] = DMRNum;
adapterPO.POData.Tables["PORel"].Rows[i]["Date01"] = adapterPO.POData.Tables["PODetail"].Rows[i]["DueDate"] ;//Delivery Date
adapterPO.Update();
}
i++;
Line++;
}
if (POLimit==1)
{
adapterPO.POData.Tables["POHeader"].Rows[0]["Approve"] = true;
adapterPO.POData.Tables["POHeader"].Rows[0]["ApprovalStatus"] = "A";
}
else
{
adapterPO.POData.Tables["POHeader"].Rows[0]["ApprovalStatus"] = "P";
}
adapterPO.Update();
// Cleanup Adapter Reference
adapterPO.Dispose();
} catch (System.Exception ex)
{
ExceptionBox.Show(ex);
}
}