0
votes

I am using Acumatica 2020 R1. I have a custom text field on the PMQuote DAC. This field is in a custom tab on the project quotes screen. I want that field to always be editable. I put the following in my RowSelected event:

    protected virtual void PMQuote_RowSelected(PXCache cache, PXRowSelectedEventArgs e, PXRowSelected del)
    {
        del?.Invoke(cache, e);
        PMQuote quote = e.Row as PMQuote;

        cache.AllowUpdate = true;
        PXUIFieldAttribute.SetEnabled(cache, e.Row, true);
        PXUIFieldAttribute.SetEnabled<PMQuoteExt.usrMyCustomField>(cache, e.Row, true);
    }

This didn't work, so I also looked in the automation steps. I didn't see any automation steps available to modify.

I then looked at Workflow. I didn't see any workflows to edit either. I tried creating a new one based on the status field. I added the user field for each status and made sure disabled was unchecked. This didn't work either.

Any ideas on how I can get that field to be enabled regardless of the document status?

Thanks for your help!

1

1 Answers

1
votes

AllowUpdate is called only on the cache object, add it for the data view, example:

Base.Quote.AllowUpdate = true

Also, try to extend PXQuoteMaintExt graph extension:

public class PMQuoteMaintExtExtension : PXGraphExtension<PMQuoteMaintExt, PMQuoteMaint>
{
    protected virtual void PMQuote_RowSelected(PXCache sender, PXRowSelectedEventArgs e, PXRowSelected sel)
    {
        sel?.Invoke(sender, e);
    }
}

It manages visibility with RowSelected event:

namespace PX.Objects.PM
{
    public class PMQuoteMaintExt : PXGraphExtension<PMDiscount, PMQuoteMaint>
    {
        protected virtual void PMQuote_RowSelected(PXCache sender, PXRowSelectedEventArgs e, PXRowSelected sel)
        {
            sel?.Invoke(sender, e);

            var row = e.Row as PMQuote;
            if (row == null) return;

            VisibilityHandler(sender, row);
        }

        private void VisibilityHandler(PXCache sender, PMQuote row)
        {
            CR.Standalone.CROpportunityRevision revisionInDb = PXSelectReadonly<CR.Standalone.CROpportunityRevision,
                Where<CR.Standalone.CROpportunityRevision.noteID, Equal<Required<CR.Standalone.CROpportunityRevision.noteID>>>>.Select(Base, row.QuoteID).FirstOrDefault();
            CR.Standalone.CROpportunity opportunityInDb = (revisionInDb == null) ? null : PXSelectReadonly<CR.Standalone.CROpportunity,
                Where<CR.Standalone.CROpportunity.opportunityID, Equal<Required<CR.Standalone.CROpportunity.opportunityID>>>>.Select(Base, revisionInDb.OpportunityID).FirstOrDefault();

            CR.Standalone.CROpportunity opportunity = PXSelect<CR.Standalone.CROpportunity,
                Where<CR.Standalone.CROpportunity.opportunityID, Equal<Required<CR.Standalone.CROpportunity.opportunityID>>>>.Select(Base, row.OpportunityID).FirstOrDefault();

            var opportunityIsClosed = opportunity?.IsActive == false;

            bool allowUpdate = row.IsDisabled != true && !opportunityIsClosed && row.Status != PMQuoteStatusAttribute.Closed;

            if (opportunityInDb?.OpportunityID == opportunity?.OpportunityID)
                Base.Caches[typeof(PMQuote)].AllowUpdate = allowUpdate;
            else
            {
                var quoteCache = Base.Caches[typeof(PMQuote)];
                foreach (var field in quoteCache.Fields)
                {
                    if (!quoteCache.Keys.Contains(field) && 
                        field != quoteCache.GetField(typeof(PMQuote.opportunityID)) &&
                        field != quoteCache.GetField(typeof(PMQuote.isPrimary)))
                        PXUIFieldAttribute.SetEnabled(sender, row, field, allowUpdate);
                }
            }

            PXUIFieldAttribute.SetEnabled<PMQuote.bAccountID>(sender, row, row.OpportunityID == null);

            Base.Caches[typeof(PMQuote)].AllowDelete = !opportunityIsClosed;
            foreach (var type in new[]
            {
                    typeof(CR.CROpportunityDiscountDetail),
                    typeof(CR.CROpportunityProducts),
                    typeof(CR.CRTaxTran),
                    typeof(CR.CRAddress),
                    typeof(CR.CRContact),
                    typeof(CR.CRPMTimeActivity),
                    typeof(PM.PMQuoteTask)
                })
            {
                Base.Caches[type].AllowInsert = Base.Caches[type].AllowUpdate = Base.Caches[type].AllowDelete = allowUpdate;
            }

            Base.Caches[typeof(CopyQuoteFilter)].AllowUpdate = true;

            Base.Caches[typeof(RecalcDiscountsParamFilter)].AllowUpdate = true;

            Base.Actions[nameof(Base.Approval.Submit)]
                .SetVisible(row.Status == PMQuoteStatusAttribute.Draft);

            Base.actionsFolder
                .SetVisible(nameof(Base.Approval.Approve), Base.Actions[nameof(Base.Approval.Approve)].GetVisible());

            Base.actionsFolder
                .SetVisible(nameof(Base.Approval.Reject), Base.Actions[nameof(Base.Approval.Reject)].GetVisible());

            Base.Actions[nameof(EditQuote)]
                .SetVisible(row.Status != PMQuoteStatusAttribute.Draft);

            Base.Actions[nameof(Base.Approval.Submit)]
                .SetEnabled(row.Status == PMQuoteStatusAttribute.Draft && !opportunityIsClosed);

            Base.Actions[nameof(Base.Approval.Approve)]
                .SetEnabled(row.Status == PMQuoteStatusAttribute.PendingApproval);

            Base.Actions[nameof(Base.Approval.Reject)]
                .SetEnabled(row.Status == PMQuoteStatusAttribute.PendingApproval);

            Base.Actions[nameof(EditQuote)]
                .SetEnabled(row.Status != PMQuoteStatusAttribute.Draft && row.Status != PMQuoteStatusAttribute.Closed);

            Base.Actions[nameof(Base.CopyQuote)]
                .SetEnabled(Base.Caches[typeof(PMQuote)].AllowInsert);

            Base.Actions[nameof(PMDiscount.GraphRecalculateDiscountsAction)]
                .SetEnabled((row.Status == PMQuoteStatusAttribute.Draft));

            Base.Actions[nameof(Base.PrimaryQuote)].SetEnabled(!String.IsNullOrEmpty(row.OpportunityID) && row.IsPrimary == false && row.Status != PMQuoteStatusAttribute.Closed);
            Base.Actions[nameof(Base.SendQuote)].SetEnabled(row.Status.IsIn<string>(PMQuoteStatusAttribute.Approved, PMQuoteStatusAttribute.Sent, PMQuoteStatusAttribute.Closed));
            Base.Actions[nameof(Base.PrintQuote)].SetEnabled(true);
            Base.convertToProject.SetEnabled( (row.OpportunityID == null || row.IsPrimary == true) && row.QuoteProjectID == null && row.Status.IsIn<string>(PMQuoteStatusAttribute.Approved, PMQuoteStatusAttribute.Sent));

            PXUIFieldAttribute.SetEnabled<PMQuote.subject>(sender, row, true);
            PXUIFieldAttribute.SetEnabled<PMQuote.status>(sender, row, false);
        }
    }
}