Skip to main content

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

        public PXAction<RecordsToProcessFilter> Rebuild;
        PXButton(CommitChanges = true)]
        rPXUIField(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.

 

 

@joe21 , Hi!

 

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


@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.


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.  😁


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;
                tPXUIField(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");
        }
 

 


Hi @joe21 

 

Maybe doing this:

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

 


@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