[RPG/JS] Using setTimout
Posted: Wed May 31, 2017 5:20 am
Is it possible to use the setTimeOut javascript function within LongRange. What I'm trying to accomplish is that when a driver completes a delivery, the upload process would initiate in the event that the server is reachable. But in the event that the server is not reachable, I was trying to set up a periodical check so that when the server is reachable, then the upload would initiate. What I got doesn't work and it actually locks up LongRange I'm assuming is because I am closing the form so the driver can continue on.
Code: Select all
save = function () {
this.lrexec(
function () {
this.q_checkServerReachable(5);
},
function (reachable) {
if (reachable == true) {
// Delay 2 second to give current process time to finish
delay(2000);
} else {
delay(60 * 1000);
}
},
function () {
this.q_setProperty("RunOperation.Type", "CloseForm");
},
function () {
this.q_apply();
},
function () {
this.q_setProperty("RunOperation.Type", "CloseForm");
},
null
);
}
delay = function (delayTime) {
setTimeout(function () {
this.lrexec(
function () {
this.q_checkServerReachable(5);
},
function (reachable) {
if (reachable == true) {
upload();
} else {
delay(delayTime);
}
},
null
);
}, delayTime);
}
upload = function () {
this.lrexec(
function () {
this.console("Uploading...");
this.q_setProperties({
"RunOperation.Type": "PerformAction",
"RunOperation.Pgm": "MOR3598",
"RunOperation.Action": "",
"RunOperation.SendDBData": "Y"
});
},
null
);
}