How to setup a requester on a landing page to refresh the data in background?

4 minute read time.

It’s great when I get asked a question which I think has an easy answer, only to find it is not as simple as I thought!  This blog is inspired from one such question, which I hope you will find interesting.

Business requirement

The business requirement sounds relatively simple, in that a customer has a requester that has been added to a landing page which they want to be as up to date as possible.  The complication is that it takes about 15 seconds to refresh the data, so they didn’t want to set the frequency on the menu item as this would slow down page rendering every time the user went back to the home page.  

The question is simply, how do I setup a requester on a landing page to refresh in background, so it is up to date when the user sees it but they don’t have to wait 15 seconds every time.

Where to start

My initial thought was to use the batch task CALALH as described in the online help “Create Requests” however the customer had already tried this and it didn’t work.   The problem with CALALH is that is updates the data for the requester in ALISTER table, which is used for classic interface only. With menu items it is looking at the JSON file in “..\Folders\..\RQT\“ directory.  This JSON file is only refreshed on request (i.e. when user displays the page or clicks refresh button) although it is also refreshed by the SYRAREP batch job as described in the online help “Supervisor Administration Requester

The problem with SYRAREP batch task is that it doesn’t work when called through the front end, as it is lacking a mandatory parameter!

My first possible solution was to use Batch Server Parameters (ABATPAR) to allow use of batch files and then use a batch file outside of X3 to create the job files to execute every minute, and although it does work it seems a bit clunky.    My next idea was to create a X3 script which will create a batch job using the function ASYRMNGTREQ.CRERQTLAN and then I can schedule this through X3 batch server to execute as a recurring task however often is required.  This seems to work much better and so am sharing this solution with you on this blog article.

Setup recurring batch job

On my test system I didn’t have any batch jobs running, so am setting up a random recurring tasks to give me some data to check my results against.

 

Setup custom view

I want a simple requestor that can quickly and easily be setup to prove the correct data is being picked up.  I therefore decided to use the batch job table as this is easy to create data in and check results, so will create a view to pick up this data.

Setup Requester

The technique being used in this article can be used for any requester you like, but in my case I am creating a custom requester based on my custom view to test the concept works as expected.

Create menu item for the requester

 

Add requester to the home page

I want to ensure all users who have access to the requester see the results in the same way, so will  add the menu item to two different users home pages, ”Admin” and “Mike” in my example.

Also check from the “Show advanced fields” when the data was last refreshed.

Can quickly check the results are as expected by using the SQL below to review the data in the source table:

select NUMREQ_0, TACHE_0, CREDATTIM_0
from X3.ABATRQT
order by 1 desc

Finally, check the “ZMBATCH_1.req” file in the “..\folders\SEED\RQT” directory reflects the same data.  This file is the source of the data being shown on the landing page.

 

I did not put in any frequency to refresh the data on the menu item setup, so the data will not refresh by default unless I click the refresh button.

As I want the refresh to happen in background at regular intervals, I need to take some action in order to achieve this requirement.   The next section provides this mechanism.

Setup custom script and recurring task to refresh the data in background

Copy “ZMSYRAREP.src” to directory “..\folders\SEED\TRT”, go into script editor and compile this script.    The script is not doing anything too complicated and is based on the example script in the online help “Launch a batch execution request

Create new task in Task Management

  

Setup this task to run as a recurring task every minute, or whatever time period you require.

Once the scheduled task has run, you should see the “ZMBATCH_1.req” file is updated without any user interaction, and users now always see the updated data as required by the business requirement.

Conclusion

Hopefully you will find this article useful, please let me know in the comments below.