on 2022 Dec 16 9:24 PM
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
}
Request clarification before answering.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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 😞
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);
Hi Elliott,
Try removing the ().
Use this
setInterval(getLiveNumbers, 10000);
The parenthesis seems to only allow it to run once.
Thanks,
Brian
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
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.
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
User | Count |
---|---|
62 | |
7 | |
6 | |
6 | |
6 | |
5 | |
4 | |
4 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.