[RPG/JS] Using setTimout

Please do not use to report errors- use your regional help desk.
Please mark posts as being for RPG or RDMLX (LANSA) developer.
To subscribe by email, display this forum, scroll to the end and select ‘Subscribe Forum’.
Post Reply
mwilliams
Posts: 17
Joined: Thu May 18, 2017 10:34 am

[RPG/JS] Using setTimout

Post by mwilliams » Tue May 30, 2017 2:20 pm

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
    );
}

tsupartono
Posts: 289
Joined: Tue Apr 17, 2012 7:21 pm

Re: [RPG/JS] Using setTimout

Post by tsupartono » Wed May 31, 2017 4:21 am

It's unfortunately not possible to use setTimeout in that way.
We can possibly enhance LongRange so you can schedule an upload to be executed as soon as the server becomes reachable.
It should be noted however that in order for the scheduled upload to kick off, LongRange must remain active, and device shouldn't be in the sleep state.
Let us know if you'd like the enhancement to be included in the next LongRange release.

mwilliams
Posts: 17
Joined: Thu May 18, 2017 10:34 am

Re: [RPG/JS] Using setTimout

Post by mwilliams » Wed May 31, 2017 2:34 pm

I would think that it would be a nice/useful feature to be able to set up background processes

rgjohnson
Posts: 19
Joined: Wed May 09, 2012 8:55 am

Re: [RPG/JS] Using setTimout

Post by rgjohnson » Wed May 31, 2017 4:14 pm

As Mike said, we definitely want to be able to automate upload processes once a connection is established. My question on this is, would the solution you are thinking of be specifically for uploads or is there a way for us to specify the function to perform when the server becomes available. We may want to upload data to the server, retrieve data from the server, check the status of something on the server and pop a message/alert up to the mobile device user, etc..

In a perfect world ( never hurts to try for perfect :-) ) we would be able to have a "scheduled" process that would execute on a pre-determined schedule and not just based on the server re-establishing a connection. We have processes we want to kick off on a standard schedule even if the user is not actively doing anything in the app. If a delivery driver is driving across town for 30 minutes, we would like these "scheduled" processes updating/retrieving information from the server to occur anyway. Many native apps send alerts or notifications even when I am not using the app or when the device is in sleep mode so I'm wondering if there is any way at all to allow us to create similar background processes to run. Our processes would then check for server availability and act accordingly, but the process would activate on a predetermined schedule or frequency.

tsupartono
Posts: 289
Joined: Tue Apr 17, 2012 7:21 pm

Re: [RPG/JS] Using setTimout

Post by tsupartono » Fri Jun 02, 2017 7:24 am

Greg,

Scheduled uploads (or any other scheduled activities) can only occur when the user is not currently using the app - parallel processing of two or more operations is unfortunately out of the question (in the context of LR).
When a scheduled upload is about to run, LR will ask the user's permission to proceed. The user can either allow the upload to proceed or not. If not, the upload will be deferred for a period of time (say 10 minutes), or until the app becomes idle. If they allow the upload to proceed, they won't be able to use LR until the upload process completes.

In regards to "true" background process (that kicks off periodically even when the device is in sleep state) - we will investigate further in terms of what the OS allows. In the past, Apple's iOS imposes a very strict rule on what a background process can do, and how long it is allowed to execute.

Post Reply