3

I have an action button on the QuoteMaint graph. This action is in the actions folder. I set whether or not the button is enabled based on the quote status. When the user submits the quote, the action button should be enabled. I stepped through the code and it runs the routine to enable button, but on the screen it is not enabled. When I refresh the screen it is enabled with no issues. The code is below, thanks for your help!

    public PXAction<CRQuote> printQuoteSummary;

    [PXButton(CommitChanges = true, SpecialType = PXSpecialButtonType.Report)]
    [PXUIField(DisplayName = "Print Quote - Summary")]
    public IEnumerable PrintQuoteSummary(PXAdapter adapter)
    {
        Dictionary<string, string> parameters = new Dictionary<string, string>();
        string actualReportID = "CR604510";

        foreach (CRQuote item in adapter.Get<CRQuote>())
        {
            parameters[nameof(CRQuote.OpportunityID)] = item.OpportunityID;
            parameters[nameof(CRQuote.QuoteNbr)] = item.QuoteNbr;

            throw new PXReportRequiredException(parameters, actualReportID, "Report " + actualReportID);
        }
        return adapter.Get();
    }

    public override void Initialize()
    {
        base.Initialize();
        Base.actionsFolder.AddMenuAction(printQuoteSummary);
        Base.Actions.Move("PrintQuote", "printQuoteSummary");
        printQuoteSummary.SetEnabled(Base.Quote.Current?.Status == CRQuoteStatusAttribute.Approved || Base.Quote.Current?.Status == CRQuoteStatusAttribute.Sent);
    }

    protected virtual void CRQuote_RowSelected(PXCache cache, PXRowSelectedEventArgs e)
    {
        CRQuote quote = e.Row as CRQuote;
        if (quote == null) return;

        using (new PXConnectionScope())
        {
            CalcTotals(quote);
        }

        printQuoteSummary.SetEnabled(quote.Status == CRQuoteStatusAttribute.Approved || quote.Status == CRQuoteStatusAttribute.Sent);
    }
  • 1
    Is your `CalcTotals` method doing requests to the database? If yes, then you will need to move this logic to FieldSelecting event handler. Acumatica doesn't allow to send requests to the database in RowSelected event handler. – Samvel Petrosov Aug 20 '19 at 17:56
  • Hi Samvel - It is not doing transactions against the database. It is for setting non-persisting fields. In thinking about this more... I'm not sure why I needed a new PXConnectionScope()... I put that in a while ago, so I may need to look into that. Thanks! – Daniel Saffo Aug 20 '19 at 18:51

1 Answers1

1

Adding the additional argument for the event delegate resolved the issue in testing, please find sample below.

    protected virtual void CRQuote_RowSelected(PXCache cache, PXRowSelectedEventArgs e, PXRowSelected del)
    {
        del?.Invoke(cache, e);
        CRQuote quote = e.Row as CRQuote;
        if (quote == null) return;

        using (new PXConnectionScope())
        {
            CalcTotals(quote);
        }
        PrintQuoteSummary.SetEnabled(quote.Status == CRQuoteStatusAttribute.Approved || quote.Status == CRQuoteStatusAttribute.Sent);
    }

With this you may also remove reference to enable/disable in your initialize method as such it would be as follows.

    public override void Initialize()
    {
        base.Initialize();
        Base.actionsFolder.AddMenuAction(PrintQuoteSummary);
        Base.Actions.Move("PrintQuote", "printQuoteSummary");
    }
Joshua Van Hoesen
  • 1,684
  • 15
  • 30
  • 1
    Thanks Joshua, that worked perfectly! I removed the line from the initialize method too. I meant to take that out before and didn't realize I had left it in. Again, thanks so much for the assistance! – Daniel Saffo Aug 19 '19 at 18:14