这可能是一个愚蠢的问题,但它确实给我带来了很多痛苦。 要求是从Opportunity添加Create Request按钮。执行验证以确保没有为当前机会创建任何请求。我在CROpportunity DAC上添加了自定义字段UsrReqNbr,以构建Opportunity和Request之间的关系。尝试使用以下方法读取扩展字段的所有方法:
1. CROpportunityExt oppExt = opportunity.GetExtension<CROpportunityExt>();
2. CROpportunityExt oppExt = Base.Opportunity.Cache.GetExtension<CROpportunityExt>(opportunity);
3. CROpportunityExt oppExt = Base.Caches[typeof(CROpportunity)].GetExtension<CROpportunityExt>(opportunity);
但没有成功。请关于如何在Action Delegate
上阅读DAC扩展的建议代码定义如下:
public PXAction<PX.Objects.CR.CROpportunity> createRQRequest;
[PXButton(CommitChanges = true)]
[PXUIField(DisplayName = "Create Request")]
public virtual IEnumerable CreateRQRequest(PXAdapter adapter)
{
foreach (CROpportunity opportunity in adapter.Get())
{
Customer customer = (Customer)PXSelect<Customer, Where<Customer.bAccountID, Equal<Current<CROpportunity.bAccountID>>>>.Select(Base, opportunity.BAccountID);
if (customer == null)
{
throw new PXException("Prospect Not Customer");
}
CROpportunityExt oppExt = PXCache<CROpportunity>.GetExtension<CROpportunityExt>(opportunity);
if (!string.IsNullOrEmpty(oppExt.UsrReqNbr))
{
throw new PXException("Yess, successfully read");
RQRequest req = PXSelect<RQRequest,
Where<RQRequest.orderNbr, Equal<Current<CROpportunityExt.usrReqNbr>>>>.Select(Base, oppExt.UsrReqNbr);
if (req == null)
{
WebDialogResult result = Base.Opportunity.View.Ask(opportunity, PXMessages.LocalizeFormatNoPrefix("Create Request Confirmation"), PXMessages.LocalizeFormatNoPrefix("Create Request for this Opportunity?"), MessageButtons.YesNo, MessageIcon.Question);
if (result == WebDialogResult.Yes)
{
oppExt.UsrReqNbr = null;
}
}
else
{
WebDialogResult result = Base.Opportunity.View.Ask(opportunity, PXMessages.LocalizeFormatNoPrefix("Create Request Confirmation"), Messages.OrderView, MessageButtons.YesNo, MessageIcon.Question);
if (result == WebDialogResult.Yes)
{
RQRequestEntry docgraph = PXGraph.CreateInstance<RQRequestEntry>();
docgraph.Document.Current = req;
throw new PXRedirectRequiredException(docgraph, "");
}
throw new PXException(Messages.OrderAlreadyCreated);
}
}
else
{
throw new PXException("Nooo, can't read the extensions");
}
答案 0 :(得分:0)
我在你的代码中注意到没有错或奇怪。请求CROpportunity DAC扩展实例时抛出的任何错误?或者你总是得到null而不是DAC扩展?
我猜,由于Acumatica运行时编译和.Net运行时的工作原理,我不时会遇到奇怪的事情。通常重启IIS有助于彻底解决此类问题。您是否可以在您的开发者计算机上重新启动IIS,如果问题仍然存在,请更新问题以及其他详细信息?