Solved

how to keep process running until we stop manually.

  • 16 December 2021
  • 2 replies
  • 118 views

Userlevel 2
Badge

we are have a requirement to read the data from external API and add to grid, this should repeat in every 5 seconds and stop when we clicked stop.


Can someone please guide me the correct way to do this.

So, we created two buttons START and STOP and also a method to read from API and insert to grid.

Issue we are facing is - on start, say we are inserting 2 records, when we clicked on stop button, the records in the grid the getting duplicated, i mean, total 4 records.

Please have a look at below code.

 public PXAction<DAC> startRead;
        [PXUIField(DisplayName = "Start Scan", MapEnableRights = PXCacheRights.Update, MapViewRights = PXCacheRights.Select)]
        [PXButton(CommitChanges = true)]
        public virtual IEnumerable StartRead(PXAdapter adapter) 
        {
            System.Threading.Thread.Sleep(5000);

            //cntLoop is unbound field with propery [PXUnboundDefault(true, PersistingCheck = PXPersistingCheck.Nothing)]
            if (this.Document.Current.CntLoop == true)
            {
                PXLongOperation.StartOperation(this, delegate ()
                {
                    AddItemsToGrid();
                });
            }
            else
                this.Save.Press();

            return adapter.Get();
        }

 

 public PXAction<DAC> stopRead;
        [PXUIField(DisplayName = "Stop Scan", MapEnableRights = PXCacheRights.Update, MapViewRights = PXCacheRights.Select)]
        [PXButton()]
        public virtual IEnumerable StopRead(PXAdapter adapter)
        {
            this.Document.Current.CntLoop = false;

            RFIDScanStart(adapter);

            return adapter.Get();
        }
 

private void AddItemsToGrid()
{
    //here we are reading data and inserting into grid

    PXAdapter adapter = new PXAdapter(new PXView(this, true, this.Document.View.BqlSelect));

    RFIDScanStart(adapter);
}

icon

Best answer by Hughes Beausejour 17 December 2021, 01:53

View original

2 replies

Userlevel 7
Badge +5

In my opinion the process must be redesigned. 

I don’t think it fits well in the way the framework works. 

 

 

Userlevel 5
Badge +2

For an example of a similar pattern, check “Refresh Results” action in Request Profiler page (SM205070):
https://help-2021r2.acumatica.com/Help?ScreenId=ShowWiki&pageid=e7612f3f-fc6f-494d-8532-cc2ceef7147b

This page avoids the 5 seconds ajax refresh calls by having the end-user manually click on the refresh results button.

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