首页 文章

Acumatica警告消息仅影响装运屏幕SO302000

提问于
浏览
1

每次ShippedQty字段在“Shipment - SO302000”屏幕上更改为值<OrigOrderQty时,我都会尝试显示警告,但我只希望代码对该特定屏幕/表单有效 .

我添加了下面的代码来扩展SOShipmentEntry图,它完成了我的原始目标,但问题是现在我添加的代码也被“Sales Orders - SO301000”屏幕/表单中的“Create Shipment”操作使用 .

Create Shipment Action Discussed

namespace PX.Objects.SO
{
  public class SOShipmentEntry_Extension : PXGraphExtension<SOShipmentEntry>
{
  #region Event Handlers

  protected void SOShipLine_ShippedQty_FieldUpdated(PXCache cache,PXFieldUpdatedEventArgs e)
{


         var myrow = (SOShipLine)e.Row;
            if (myrow == null) return;


                if (myrow.ShippedQty >= myrow.OrigOrderQty)
                {

                }
            else
            {
                throw new PXSetPropertyException("The difference between the shipped-qty and the ordered-qty will be placed on a back-order", PXErrorLevel.Warning);
            }  

}


  #endregion
 }
}

虽然警告允许用户在发货屏幕/表格SO302000上保存对货件的更改(因为例外设置为警告而非错误),当我使用“创建货件”创建货件时出现以下错误“销售订单 - SO301000”屏幕上的“按钮 .

Warning works fine for form-mode

Warning becomes error when processed in background by action button

任何想法来实现这一目标?我的理解是,如果我想对一个字段进行全局更改,我必须在DAC中进行,但是如果我想进行仅影响使用图形的屏幕/表单的更改,那么我必须在图形代码本身 . 我猜测销售订单屏幕中的“创建货件”操作按钮正在创建我添加代码的图形实例,所以我想知道我的选项是什么 .

最好的祝福,

  • Acumatica新手

1 回答

  • 0

    如果您希望仅在从“货件”屏幕调用CreateShipment时执行事件逻辑,则可以覆盖对CreateShipment的其他调用以动态删除事件处理程序 .

    从SalesOrderEntry图中调用CreateShipment操作的事件是Action:

    public PXAction<SOOrder> action;
    [PXUIField(DisplayName = "Actions", MapEnableRights = PXCacheRights.Select)]
    [PXButton]
    protected virtual IEnumerable Action(PXAdapter adapter,
        [PXInt]
        [PXIntList(new int[] { 1, 2, 3, 4, 5 }, new string[] { "Create Shipment", "Apply Assignment Rules", "Create Invoice", "Post Invoice to IN", "Create Purchase Order" })]
        int? actionID,
        [PXDate]
        DateTime? shipDate,
        [PXSelector(typeof(INSite.siteCD))]
        string siteCD,
        [SOOperation.List]
        string operation,
        [PXString()]
        string ActionName
        )
    

    在该方法中,它创建一个SOShipmentEntry图以创建货件 . 您可以覆盖Action并从该图形实例中删除处理程序:

    SOShipmentEntry docgraph = PXGraph.CreateInstance<SOShipmentEntry>();
    
    // >> Remove event handler
    SOShipmentEntry_Extension docgraphExt = docgraph.GetExtension<SOShipmentEntry_Extension>();
    docgraph.FieldUpdated.RemoveHandler<SOShipLine.shippedQuantity>(docgrapExt.SOShipLine_ShippedQty_FieldUpdated);
    // << Remove event handler
    
    docgraph.CreateShipment(order, SiteID, filter.ShipDate, adapter.MassProcess, operation, created);
    

    请注意,为了从另一个图表中引用SOShipLine_ShippedQty_FieldUpdated方法,您必须将其公开:

    public void SOShipLine_ShippedQty_FieldUpdated(PXCache cache,PXFieldUpdatedEventArgs e)
    

    我已经在这个答案中描述了如何做到这一点:Updating custom field is ending into infinite loop


    如果您希望事件逻辑仅在UI或Web服务中修改时执行 .

    您可以使用PXFieldUpdatedEventArgs参数的ExternalCall Boolean属性 . 仅当在UI中或通过Web服务修改sender字段时,此属性值才为true .

    用法示例:

    protected void SOShipLine_ShippedQty_FieldUpdated(PXCache cache,PXFieldUpdatedEventArgs e)
    {
       // If ShippedQty was updated in the UI or by a web service call
       if (e.ExternalCall)
       {
          // The logic here won't be executed when CreateShipment is invoked
       }
    }
    

    ExternalCall Property (PXFieldUpdatedEventArgs)

    获取指定是在UI中还是通过Web Service API更改当前DAC字段的新值的值 .

相关问题