Acumatica CropportUnityText数据未保存
你好 我在CROpportunity扩展中有一个新的领域,叫做usrGrossProfit。 在CropOpportunity的RowSelected中,它会根据需要计算出值。我遇到的问题是,用户正在表单上使用createquote按钮,因此从不使用save按钮进行保存,系统会为他们进行保存。我发现,正因为如此,usrGrossProfit值没有保存 是否有办法在RowSelected函数中强制保存/持久化Acumatica CropportUnityText数据未保存,acumatica,Acumatica,你好 我在CROpportunity扩展中有一个新的领域,叫做usrGrossProfit。 在CropOpportunity的RowSelected中,它会根据需要计算出值。我遇到的问题是,用户正在表单上使用createquote按钮,因此从不使用save按钮进行保存,系统会为他们进行保存。我发现,正因为如此,usrGrossProfit值没有保存 是否有办法在RowSelected函数中强制保存/持久化 protected void CROpportunity_RowSelected(PXC
protected void CROpportunity_RowSelected(PXCache cache, PXRowSelectedEventArgs e)
{
try
{
var row = (CROpportunity)e.Row;
if (row == null) return;
CROpportunityExt SOE = PXCache<CROpportunity>.GetExtension<CROpportunityExt>(row);
int total = 0;
decimal TotalSales = 0;
decimal TotalCost = 0;
foreach (CROpportunityProducts item in this.Base.Products.Select())
{
total++;
CROpportunityProductsExt2 itemExt = PXCache<CROpportunityProducts>.GetExtension<CROpportunityProductsExt2>(item);
TotalCost += (decimal)itemExt.UsrCostPrice.Value * item.Qty.Value;
TotalSales += (decimal)itemExt.UsrSellingprice * item.Qty.Value;
}
SOE.UsrGrossProfit = TotalSales - TotalCost;
// I added this just to try and see if it helps
cache.SetValueExt<CROpportunityExt.usrGrossProfit>(row, (decimal)(TotalSales - TotalCost));
// we are not allowed to press the save button in the event Handler
//this.Base.Save.Press();
}
catch (Exception ex)
{
PXTrace.WriteError(ex);
}
}
我还制作了一个业务活动来打开并保存Opportunity,但运气不佳。不,即使允许,您也不应该在选定的行上保存。这是因为行所选事件被激发多次,并且您不希望每次都保存 如果要在CreateQuote覆盖上保存,请尝试以下操作:
Base.Save.PressButton(adapter)
也许更好的选择是强制用户,让用户自己保存。例如,您可以检查状态并在覆盖中抛出错误,而不是保存
if (Opportunity.Current != null && Opportunity.Cache.GetStatus(Opportunity.Current) == PXEntryStatus.Inserted)
{
throw new PXException("Please save before proceeding");
}
谢谢Joseph,我会尝试这两种方法,看看哪种方法最有效。这个问题可能与你的逻辑无关,而是与你的预测机会有关。当您直接按Save键时,能否确认记录是否已保存?不调用保存。按入选定的行。从UI透视图测试它是的,如果使用按钮,它会正常保存。我不知道投影是什么?有没有一个地方我可以读得更多一点呢?这是一个相当于SQL视图的BQL,但它也可以用于其他目的。以下是一篇包含更多信息的文章:
if (Opportunity.Current != null && Opportunity.Cache.GetStatus(Opportunity.Current) == PXEntryStatus.Inserted)
{
throw new PXException("Please save before proceeding");
}