How to enable a custom field on AR301000 after the

2019-09-16 19:04发布

Some user fields were added to the ARInvoice entry screen (AR301000). The user fields exist in the Transactions grid. They are text fields only. There is no custom logic associated, and are bound to the DB table.

A user wishes to modify a particular user text field after the invoice is released - what would be the best way to achievee this?

1条回答
闹够了就滚
2楼-- · 2019-09-16 19:48

Thankfully, the Transactions grid on the ARInvoces entry screen is never disabled by automation steps. All UI presentation logic for the Transactions grid is only defined within the ARInvoiceEntry BLC:

public class ARInvoiceEntry : ARDataEntryGraph<ARInvoiceEntry, ARInvoice>, PXImportAttribute.IPXPrepareItems
{
    ...
    protected virtual void ARInvoice_RowSelected(PXCache cache, PXRowSelectedEventArgs e)
    {
        ARInvoice doc = e.Row as ARInvoice;
        if (doc == null) return;

        ...
        bool shouldDisable = doc.Released == true
                            || doc.Voided == true
                            || doc.DocType == ARDocType.SmallCreditWO
                            || doc.PendingPPD == true
                            || doc.DocType == ARDocType.FinCharge && !IsProcessingMode && cache.GetStatus(doc) == PXEntryStatus.Inserted;
        if (shouldDisable)
        {
            ...
            Transactions.Cache.AllowDelete = false;
            Transactions.Cache.AllowUpdate = false;
            Transactions.Cache.AllowInsert = false;
            ...
        }
        else
        {
            ...
            Transactions.Cache.AllowDelete = true;
            Transactions.Cache.AllowUpdate = true;
            Transactions.Cache.AllowInsert =
                doc.CustomerID != null &&
                doc.CustomerLocationID != null &&
                doc.DocType != ARDocType.FinCharge &&
                (doc.ProjectID != null || !PM.ProjectAttribute.IsPMVisible(this, BatchModule.AR));
            ...
        }
        ...
    }

    protected virtual void ARTran_RowSelected(PXCache sender, PXRowSelectedEventArgs e)
    {
        ARTran row = e.Row as ARTran;
        if (row != null)
        {
            PXUIFieldAttribute.SetEnabled<ARTran.defScheduleID>(sender, row, row.TranType == ARInvoiceType.CreditMemo || row.TranType == ARInvoiceType.DebitMemo);
            PXUIFieldAttribute.SetEnabled<ARTran.deferredCode>(sender, row, row.DefScheduleID == null);
        }
    }
    ...
}

To enable a custom field on AR301000 after the ARInvoice is released, you should complete the following relatevely simple steps:

  1. Set AllowUpdate to true for the ARTran cache within the ARInvoice_RowSelected event handler

  2. Invoke the static PXUIFieldAttribute.SetEnabled method to disable all ARTran fields, except the particular custom text field, the user wants to modify

enter image description here

The complete code snippet is listed below:

public class ARInvoiceEntryExt : PXGraphExtension<ARInvoiceEntry>
{
    private bool IsDisabled(ARInvoice doc)
    {
        return doc.Released == true
            || doc.Voided == true
            || doc.DocType == ARDocType.SmallCreditWO
            || doc.PendingPPD == true
            || doc.DocType == ARDocType.FinCharge 
            && !Base.IsProcessingMode 
            && Base.Document.Cache.GetStatus(doc) == PXEntryStatus.Inserted;
    }

    public void ARInvoice_RowSelected(PXCache cache, PXRowSelectedEventArgs e)
    {
        ARInvoice doc = e.Row as ARInvoice;
        if (doc == null) return;

        if (IsDisabled(doc))
        {
            Base.Transactions.Cache.AllowUpdate = true;
        }
    }

    public void ARTran_RowSelected(PXCache sender, PXRowSelectedEventArgs e)
    {
        var doc = Base.Document.Current;
        ARTran row = e.Row as ARTran;

        if (row != null && doc != null && IsDisabled(doc))
        {
            PXUIFieldAttribute.SetEnabled(sender, row, false);
            PXUIFieldAttribute.SetEnabled<ARTranExt.usrCustomTextField>(sender, row, true);
        }
    }
}
查看更多
登录 后发表回答