Solved

How do I simply open a new Screen ID from an action on a custom page?

  • 9 January 2023
  • 6 replies
  • 314 views

Userlevel 6
Badge +3

On my custom page, I have an action to open the Recalculate Customer Balances screen (AR509900)

        public PXAction<RecordsToProcessFilter> Rebuild;
        [PXButton(CommitChanges = true)]
        [PXUIField(DisplayName = "Rebuild Accounts")]
        protected virtual IEnumerable rebuild(PXAdapter adapter)
        {
            var graph = PXGraph.CreateInstance<ARIntegrityCheck>();

            throw new PXRedirectRequiredException(graph, false,
                    "Rebuild Accounts");
        }

 

There are two versions of this screen.  The new one and the (old) one.

When the graph gets instantiated, the highlighted line sees the screen being called from IC501010, not AR509900.  Thus, it kicks me to the else section and uses the OLD way of doing it.  It actually opens screen ID AR509901.  The arReleaseGraph actually errors out when recalculating a customer in the U100 sample data, whereas the new way does not.  Plus, the new way is a LOT faster.

protected virtual void _(Events.RowSelected<ARIntegrityCheckFilter> e)
        {
            ARIntegrityCheckFilter filter = Filter.Current;

 

            bool errorsOnForm = PXUIFieldAttribute.GetErrors(e.Cache, null, PXErrorLevel.Error, PXErrorLevel.RowError).Count > 0;

a            PXUIFieldAttribute.SetRequired<ARIntegrityCheckFilter.finPeriodID>(e.Cache, filter.RecalcDocumentBalances == true || filter.RecalcCustomerBalancesReleased == true);

            ARCustomerList.SetProcessEnabled(!errorsOnForm);
            ARCustomerList.SetProcessAllEnabled(!errorsOnForm);
            ARCustomerList.SuppressMerge = true;
            ARCustomerList.SuppressUpdate = true;

            if (this.Accessinfo.ScreenID == RECALCULATE_CUSTOMER_BALANCES_SCREEN_ID)
            {
                ARCustomerList.SetProcessDelegate(
                    delegate (ARIntegrityCheck integrityCheckGraph, Customer cust)
                    {
                        integrityCheckGraph.Clear(PXClearOption.PreserveTimeStamp);
                        integrityCheckGraph.IntegrityCheckProc(cust, filter);
                    }
                );

                ARCustomerList.SetParametersDelegate(delegate (List<Customer> list)
                {
                    if (
                        filter.RecalcDocumentBalances != true &&
                        filter.RecalcCustomerBalancesReleased != true &&
                        filter.RecalcCustomerBalancesUnreleased != true)
                    {
                        throw new PXException(Messages.SelectBalancesToBeRecalculated);
                    }
                    return true;
                });
            }
            else
            {
                ARCustomerList.SetProcessDelegate<ARReleaseProcess>(
                    delegate (ARReleaseProcess arReleaseGraph, Customer cust)
                    {
                        arReleaseGraph.Clear(PXClearOption.PreserveTimeStamp);
                        arReleaseGraph.IntegrityCheckProc(cust, filter.FinPeriodID);
                    }
                );

                //For perfomance recomended select not more than maxCustomerCount customers, 
                //becouse the operation is performed for a long time.
                const int maxCustomerCount = 5;
                ARCustomerList.SetParametersDelegate(delegate (List<Customer> list)
                {
                    bool processing = true;
                    if (PX.Common.PXContext.GetSlot<PX.SM.AUSchedule>() == null && list.Count > maxCustomerCount)
                    {
                        WebDialogResult wdr = ARCustomerList.Ask(Messages.ContinueValidatingBalancesForMultipleCustomers, MessageButtons.OKCancel);
                        processing = (wdr == WebDialogResult.OK);
                        if(!processing)
                        throw new PXException(Messages.SelectBalancesToBeRecalculated);
                    }
                    return processing;
                });
            }
        }
 

How can I open AR509900 from my custom screen?  It seems like there should be a SIMPLE REDIRECT.  Is there a way I can get AR509900 to open “cleanly” and not see it as coming from my screen?

If not, I am considering copying and pasting the entire graph just to remove that IF statement.

 

 

icon

Best answer by Leonardo Justiniano 9 January 2023, 23:36

View original

6 replies

Userlevel 6
Badge +4

@joe21 , Hi!

 

Is the new screen AR509001 a totally custom one? (I mean a Copy 😀) How is the new graph set?

Userlevel 6
Badge +3

@Leonardo Justiniano

IC501020 is my screen.  If you open Recalculate Customer Balances from the menu (2022R2), it opens

 

When I open the graph from code (from my custom screen) it sees it as coming from my screen and opens this:

 

Weird huh?

It is due to the IF statement I highlighted in my original question.  

Both of the Recalculate screens are native Acumatica screens.

Userlevel 6
Badge +3

PS...this goes back to a question I asked a while back.  

I FINALLY understand what you all were trying to tell me back then.  😁

Userlevel 6
Badge +3

Not the most elegant solution, but this works.  If anyone has a nicer way to do this, I’d love to know.  This is not “happy code” to me.

        public PXAction<RecordsToProcessFilter> Rebuild;
        [PXButton(CommitChanges = true)]
        [PXUIField(DisplayName = "Rebuild Accounts")]
        protected virtual IEnumerable rebuild(PXAdapter adapter)
        {
            string url = HttpContext.Current.Request.Url.AbsoluteUri;

            url = url.Substring(0, url.IndexOf("/Pages/")) + "/Pages/AR/AR509900.aspx";

            throw new Exception($"Redirect7:{url}");

            //throw new PXRedirectRequiredException(graph, false,
            //        "Rebuild Accounts");
        }
 

 

Userlevel 6
Badge +4

Hi @joe21 

 

Maybe doing this:

string screenID = "AR509900";
throw new PXRedirectToUrlException(PXSiteMap.Provider.FindSiteMapNodeByScreenID(screenID).Url, PXBaseRedirectException.WindowMode.New, "Rebuild Accounts");

 

Userlevel 6
Badge +3

@Leonardo Justiniano Look at you being all humble...”Maybe doing this”.

That worked so well I had to run it in debug to make sure that code was the code being run!

Now that is elegant!  I was kind of hoping my solution was the only way to do it so I could vote my own answer as the solution.  :-)

Thanks again Leo.

Reply


About Acumatica ERP system
Acumatica Cloud ERP provides the best business management solution for transforming your company to thrive in the new digital economy. Built on a future-proof platform with open architecture for rapid integrations, scalability, and ease of use, Acumatica delivers unparalleled value to small and midmarket organizations. Connected Business. Delivered.
© 2008 — 2024  Acumatica, Inc. All rights reserved