cancel
Showing results for 
Search instead for 
Did you mean: 

Using setInterval() with Slipstream for Dynamic Tile Info

eedens
Participant
0 Kudos
718

I'm working on a dashboard to monitor a picklist and display the current status of various items. Ideally, I don't want to have to refresh the screen constantly. I'm planning on calling an RFC to get the values, but I'm having issues getting this to run more than once. So far, I've found the suggestion by tamas.hoznek to use setInterval() in an onLoad script, and the use case seems identical to mine, but it still only runs a single time. kmagons also has a setInterval() suggestion, but it seems to break in other ways. Has anyone successfully implemented something like this? Calling background data through web workers or some kind of a constant async script without interrupting the user session seems like a nice tool to have.

Here's an example:

/* globals setInterval, console */
setInterval(getLiveNumbers(), 10000); //run the function at 10 second intervalsfunction getLiveNumbers() {
let numVal = session.findById("wnd[0]/usr/lblPersonas_167122239434233"); //Label to display info
let oRFC = session.createRFC("MSS_GET_SY_DATE_TIME"); //Get system time RFC (standard RFC)
oRFC.requestResults(["SAPTIME"]);
oRFC.send();
let _SAPTIME = oRFC.getResult("SAPTIME");
numVal.text = String(_SAPTIME); //Update the label text
console.log(_SAPTIME); //Log the RFC return
}

Edit: Still having issues with the code box. Here's my original:

/* globals setInterval, console */

setInterval(getLiveNumbers(), 10000); //run the function at 10 second intervals

function getLiveNumbers() {

let numVal = session.findById("wnd[0]/usr/lblPersonas_167122239434233"); //Label to display info

let oRFC = session.createRFC("MSS_GET_SY_DATE_TIME"); //Get system time RFC (standard RFC)

oRFC.requestResults(["SAPTIME"]);

oRFC.send();

let _SAPTIME = oRFC.getResult("SAPTIME");

numVal.text = String(_SAPTIME); //Update the label text

console.log(_SAPTIME); //Log the RFC return

}

Accepted Solutions (1)

Accepted Solutions (1)

Tamas_Hoznek
Product and Topic Expert
Product and Topic Expert

Hi Elliott,

Try putting your RFC into a separate script and call that within the setInterval function asynchronously (via session.utils.executeScriptAsync).

Here is an example link to a flavor that uses this method. It is displaying a clock as an SMEN flavor which you can start / stop. The buttons have a little lag sometimes, so you may need to click them more than once... but this works for me.

eedens
Participant
0 Kudos

Thanks for the example! I tested it out, and the clock function works on mine too. It feels like I'm getting closer, but I still can't get it to update from an RFC. I did notice that the screen does a refresh on an RFC call (flashes & loading symbol shows for a second), so I tried attaching it to the onload event in case it's getting wiped during that, and still no luck.

Start RFC Interval

/* globals setInterval, console, window */

var r = window.setInterval(session.utils.executeScriptAsync("wnd[0]/scrptPersonas_005056A55A2B1EDD9FF97D56C6DC3908", null), 10000); //run the function at 10 second intervals

session.utils.put("R",""+ r);

console.log('Starting RFC Interval');


Asynch Script Called

/*globals console */

let oRFC = session.createRFC("MSS_GET_SY_DATE_TIME"); //Get system time RFC (standard RFC)

oRFC.requestResults(["SAPTIME"]);

oRFC.send();

let _SAPTIME = oRFC.getResult("SAPTIME");

session.findById("wnd[0]/usr/lblPersonas_16714749967805").text = String(_SAPTIME); //Update the label text

console.log(_SAPTIME); //Log the RFC return


Stop RFC Interval

/*globals console */

var r = session.utils.get("R");

window.clearInterval(r);

console.log('Stopping RFC Interval');


Edit:

I think I'm going to give up on the code boxes 😞

Tamas_Hoznek
Product and Topic Expert
Product and Topic Expert

Why give up? Try this.

eedens
Participant
0 Kudos

Sorry, I meant the markdown code boxes on this site. I'm definitely not giving up on getting this running.

eedens
Participant

That did it! I wasn't setting the script called called by the interval as a function.

wrong:

var r = window.setInterval(session.utils.executeScriptAsync(<myScript>), <time>);

right:

var r = window.setInterval(function(){ session.utils.executeScriptAsync(<myScript>); }, <time>);

The screen does the load flash and spinner. Is there any way to mitigate this?

Here are the scripts used in the working example:

//clearTime

session.findById("wnd[0]/usr/lblPersonas_167148468361838").text = 'time';

//setTime

let oRFC = session.createRFC("MSS_GET_SY_DATE_TIME"); //Get system time RFC (standard RFC)

oRFC.requestResults(["SAPTIME"]);

oRFC.send();

let _SAPTIME = oRFC.getResult("SAPTIME");

session.findById("wnd[0]/usr/lblPersonas_167148468361838").text = String(_SAPTIME); //Update the label text

//stop

var r = session.utils.get("R");

window.clearInterval(r);

//start

var r = window.setInterval(function(){ session.utils.executeScriptAsync("wnd[0]/scrptPersonas_93025DF550981EDD9FFD5999B00E7BD0"); }, 5000 ); //run the function at 5 second intervals

session.utils.put("R",""+r);

Answers (1)

Answers (1)

Brian_Wills
Contributor

Hi Elliott,

Try removing the ().

Use this

setInterval(getLiveNumbers, 10000);

The parenthesis seems to only allow it to run once.

Thanks,

Brian

eedens
Participant

Thanks Brian, that got it printing to the console, so I know it's actually running now. Still no luck getting it to update the label though.

Brian_Wills
Contributor
0 Kudos

Hi Elliot,

I've also been doing some testing and it seems inconsistent to update text on the screen too.

If I learn more I'll share my findings.

Thanks,

Brian

eedens
Participant
0 Kudos

I appreciate it, I've been trying to get this to do something all afternoon. Seeing it now doing something will help me relax this weekend. Otherwise, I'd be combing through documentation and wracking my brain on what's wrong 🙂 . Since it's been working, I've tried it on a free text field as well. So far in either place I've noticed it only updates to the second to last value, and only if I hit enter.

Brian_Wills
Contributor
0 Kudos

I think the answer from Krists for the setInterval is what you need to do. I'm not using slipstream so I cannot test this solution, but it looks like this would work for you.

I was able to get the setInterval to exeucte my script each second but could never get it to update the text on the screen.

Have a great weekend.

Thanks,

Brian