# suitescript

Suite Deal

03/23/2022, 6:19 PM
What is the recommeded process for continuously updating a front-end "results" suitelet via clientscript & back-end suitelet? 1. Front-end Suitelet Displays M/R Task status/percent 2. ClientScript is anchored to the form, and runs on Page Init 3. Back-end Suitelet is called from clientscript to get M/R Task status (via 10 second setInterval/clearInterval fetch() loop) 4. ClientScript gets new values 5. ** Recommeded process for updating the Front-end Suitelet at this point (from clientscript or back-end suitelet)? a. Is Page Init going to be a problem when trying to use window.location.reload()?


03/23/2022, 7:23 PM
Sounds like Page Init is the solution, not the problem? On page init, display results, then set interval to reload page in 10 seconds unless the user presses escape or some other trigger (a percentage bar being equal to 100%)

Suite Deal

03/23/2022, 7:36 PM
Okay, was thinking if the ClientScript executes on Page Init, and I'm using window.location.reload() inside a interval loop, wouldn't the script re-run from the beginning when the page is reloaded (page init event retriggered)?
Copy code
function pageInit(context) {

       //Get Suitelet Form Values
       var objRecord = context.currentRecord;
       var task = objRecord.getValue({fieldId:'task'});
       console.log('Task ID:', task);
       var status = objRecord.getValue({fieldId:'status'});
       console.log('Status:', status);
       var percent = objRecord.getValue({fieldId:'percent'});
       console.log('Percent Complete:', percent);

       //call Back-end Suitelet
       var suiteletURL = url.resolveScript({
         scriptId: 'customscript_backend_suitelet',
         deploymentId: 'customdeploy_backend_suitelet',
         returnExternalUrl: false,
         params: {
           'task' : task


   	   var intervalId = setInterval(function(){
         .then(response => response.json())
         .then(status => {
             console.log('Fetch Response:', status);
             if(status === 'COMPLETE' || status === 'FAILED') {
               alert('Import Process Complete. Please Check your Email for Results.');
             }//end if
           	 else {
                //set front-end suitelet ui form values;
                console.log('Status is PENDING OR PROCESSING');
       }, 5000);


03/23/2022, 11:49 PM
you can probably just set the task, status or percent in your client script
you dont need to call the suitelet again to get a new page