Alpha Software Mobile Development Tools:   Alpha Anywhere    |   Alpha TransForm subscribe to our YouTube Channel  Follow Us on LinkedIn  Follow Us on Twitter  Follow Us on Facebook

Announcement

Collapse

The Alpha Software Forum Participation Guidelines

The Alpha Software Forum is a free forum created for Alpha Software Developer Community to ask for help, exchange ideas, and share solutions. Alpha Software strives to create an environment where all members of the community can feel safe to participate. In order to ensure the Alpha Software Forum is a place where all feel welcome, forum participants are expected to behave as follows:
  • Be professional in your conduct
  • Be kind to others
  • Be constructive when giving feedback
  • Be open to new ideas and suggestions
  • Stay on topic


Be sure all comments and threads you post are respectful. Posts that contain any of the following content will be considered a violation of your agreement as a member of the Alpha Software Forum Community and will be moderated:
  • Spam.
  • Vulgar language.
  • Quotes from private conversations without permission, including pricing and other sales related discussions.
  • Personal attacks, insults, or subtle put-downs.
  • Harassment, bullying, threatening, mocking, shaming, or deriding anyone.
  • Sexist, racist, homophobic, transphobic, ableist, or otherwise discriminatory jokes and language.
  • Sexually explicit or violent material, links, or language.
  • Pirated, hacked, or copyright-infringing material.
  • Encouraging of others to engage in the above behaviors.


If a thread or post is found to contain any of the content outlined above, a moderator may choose to take one of the following actions:
  • Remove the Post or Thread - the content is removed from the forum.
  • Place the User in Moderation - all posts and new threads must be approved by a moderator before they are posted.
  • Temporarily Ban the User - user is banned from forum for a period of time.
  • Permanently Ban the User - user is permanently banned from the forum.


Moderators may also rename posts and threads if they are too generic or do not property reflect the content.

Moderators may move threads if they have been posted in the incorrect forum.

Threads/Posts questioning specific moderator decisions or actions (such as "why was a user banned?") are not allowed and will be removed.

The owners of Alpha Software Corporation (Forum Owner) reserve the right to remove, edit, move, or close any thread for any reason; or ban any forum member without notice, reason, or explanation.

Community members are encouraged to click the "Report Post" icon in the lower left of a given post if they feel the post is in violation of the rules. This will alert the Moderators to take a look.

Alpha Software Corporation may amend the guidelines from time to time and may also vary the procedures it sets out where appropriate in a particular case. Your agreement to comply with the guidelines will be deemed agreement to any changes to it.



Bonus TIPS for Successful Posting

Try a Search First
It is highly recommended that a Search be done on your topic before posting, as many questions have been answered in prior posts. As with any search engine, the shorter the search term, the more "hits" will be returned, but the more specific the search term is, the greater the relevance of those "hits". Searching for "table" might well return every message on the board while "tablesum" would greatly restrict the number of messages returned.

When you do post
First, make sure you are posting your question in the correct forum. For example, if you post an issue regarding Desktop applications on the Mobile & Browser Applications board , not only will your question not be seen by the appropriate audience, it may also be removed or relocated.

The more detail you provide about your problem or question, the more likely someone is to understand your request and be able to help. A sample database with a minimum of records (and its support files, zipped together) will make it much easier to diagnose issues with your application. Screen shots of error messages are especially helpful.

When explaining how to reproduce your problem, please be as detailed as possible. Describe every step, click-by-click and keypress-by-keypress. Otherwise when others try to duplicate your problem, they may do something slightly different and end up with different results.

A note about attachments
You may only attach one file to each message. Attachment file size is limited to 2MB. If you need to include several files, you may do so by zipping them into a single archive.

If you forgot to attach your files to your post, please do NOT create a new thread. Instead, reply to your original message and attach the file there.

When attaching screen shots, it is best to attach an image file (.BMP, .JPG, .GIF, .PNG, etc.) or a zip file of several images, as opposed to a Word document containing the screen shots. Because Word documents are prone to viruses, many message board users will not open your Word file, therefore limiting their ability to help you.

Similarly, if you are uploading a zipped archive, you should simply create a .ZIP file and not a self-extracting .EXE as many users will not run your EXE file.
See more
See less

List Control Saving to Server and when primary key is known for new record (Timing issue).

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    List Control Saving to Server and when primary key is known for new record (Timing issue).

    I have an expense app where I decoupled the image from the list SQL data source. This makes the app lighter and more efficient with heavy user load. The image is displayed on demand via an Ajax callback. If a user returns a filtered list with 40 records, chances are they are not going to look at all 40 images. Users just want to know when they get paid. Everything works great except with a poor cellular connection. The app requires a connection. This is by design. To simplify, I am only showing the code that relates to this issue.

    When the following code is executed, how do I wait until the primary key is known. It would be nice to have an option like AJAX action java script where a java script function can be executed AFTER the server update is complete. No such option exist for the saveListEdits method.

    var lObj = {dialog.object}.getControl('List_Expenses');
    lObj.updateListFromUXControls();
    {dialog.object}.saveListEdits('List_Expenses',{rows: 'current'});
    setTimeout(function(){ saveimage(); }, 4000);

    I don't try to save the image until 4 seconds have elapsed. 4 seconds is an arbitrary number. I would prefer to execute as soon as the primary key is known to avoid unnecessary delay when connection is good.

    In the saveimage() function below, I added this code to check if the ExpenseID exist to make sure my Ajax callback will save the image properly to the new record.
    When connection is decent, everything works as expected (99% of time)

    function saveimage() {

    var nExpenseID = {dialog.object}.getValue('ExpenseID');
    if(nExpenseID == '' || nExpenseID == null)
    {
    alert("The app has detected that your image may not be saved. Go back to expense list and tap details to insure your image has been saved. Retake picture if needed.");
    alert("This problem is due to bad connection. You need 2 or more bars");
    }

    var imageCtrl = {dialog.Object}.getPointer('RECEIPTIMAGE');
    var photoData = imageCtrl.src;
    var photoDataEnc = encodeURIComponent(imageCtrl.src);
    {dialog.object}.ajaxCallback('','','xbUpdateImage','','__photoData=' + photoDataEnc,{onComplete: function() }
    }

    I know there are many ways to accomplish things in Alpha. Any help or suggestions would be greatly appreciated.

    #2
    Re: List Control Saving to Server and when primary key is known for new record (Timing issue).

    It would be nice to have an option like AJAX action java script where a java script function can be executed AFTER the server update is complete. No such option exist for the saveListEdits method.
    I believe that saveListEdits basically does a synchronize list. So it seems that you could use the List's Detail View event, afterSynchronizeList, where you can run the javascript you want after.

    Comment


      #3
      Re: List Control Saving to Server and when primary key is known for new record (Timing issue).

      See if you could use the Client-side event afterAjaxCallbackComplete.

      There's some information passed into this event such as:

      ajaxEvent: "AjaxCallback"
      callbackId: whatever it is
      xbasicFunctionName: "system:persistListData"

      That xbasicFunctionName seems odd to me... since what I've just run is a {dialog.object}.saveListEdits()... and the List option to Persist Data is not turned on.

      However, if that's what comes back, you can use that and ajaxEvent to test what's going on and then run your code... or not. You may still need a bit of a timeout, but at least you'll know that the server has completed what's it's doing.

      Comment


        #4
        Re: List Control Saving to Server and when primary key is known for new record (Timing issue).

        Thanks to David and Jeff for your prompt reply. I will try the client side events and advise if problem is solved.

        Comment


          #5
          Re: List Control Saving to Server and when primary key is known for new record (Timing issue).

          Jeff's suggestion looks to be much cleaner. There are a bucket of returned parameters... very useful... and afterSynchronizeList fires after afterAjaxCallbackComplete... much better.

          Comment


            #6
            Re: List Control Saving to Server and when primary key is known for new record (Timing issue).

            I added the following code to afterSynchronizeList in the list control detail view event.
            Good News:The app is faster since I don't need to guess on the timeout between saving the new record and then updating the image.
            Bad News: It fails when connection is very poor.

            if(e.hasErrors == true)
            { alert("An error is preventing the saving of your data. Please verify your image by going back to list and tapping details"); }

            var lObj = {dialog.object}.getControl('List_Expenses');
            var errArray = lObj.getAllErrors();
            var errString = errArray.toString();
            if (errString != '') {
            alert(errString); //need a more elegant way to display errors.
            }

            if(e.recordsInserted ==1) { //execute only on insert.
            {
            setTimeout(function(){ saveimage(); },500);
            }
            }


            Unlike an AJAX callback which provides optional parameters for java script code when the AJAX fails or no connection, there doesn't seem to an event where I can make that determination that the saveListEdits method did not return a response from the server. I do know the record is still dirty, Save and Cancel are still enabled.

            When the connection is very poor, I tap "Save" and see the wait animation for a couple seconds and then it disappears. The record remains dirty. In this case, the afterSyncrhonizeList never fires. When I improve the connection, the record saves and afterSyncrhonizeList is then fired as expected.

            This is an edge case scenario that I would like tighten up since 99% of the expense images save as expected. This only applies to inserts. Updates are not an issue since I have the primary key and a simple AJAX call with error and connection handling all work as expected. This is my first enterprise app with over 320 users so I would like to improve on gracefully handing the problem with clear messaging to the user.

            This can get more complicated when server response is not returned and subsequent call backs can result in duplicate records which would involve implementing the log table which I would like to avoid. I have not had time to play with that feature.


            Last question: Is there a timeout setting for saveListEdits method?
            Note: Perhaps David's suggestion of the list control afterAjaxCallback may help but I don't think it will fire if no response is returned from the server.

            Comment


              #7
              Re: List Control Saving to Server and when primary key is known for new record (Timing issue).

              The afterAjaxCallback is not tied to the List Control... it is a UX Client-side event. There are other UX Client-side events that may be helpful in your situation... have a look.

              Comment


                #8
                Re: List Control Saving to Server and when primary key is known for new record (Timing issue).

                I could not find any list control events (List events or Detail View events) to trap for failed AJAX when executing the saveListEdits method.
                However, using the onAjaxCallbackFailed of the UX is an acceptable solution. Although it is not tied to the List control specifically, it does fire when the connection is very poor and a response did not come back from the server when I try to synchronize the list. Also, it fires for any AJAX failure for the UX. For example, if I am unable to get job or per diem information from the server, the message applies as well. Alerting the user they need to get a better connection will solve these rare problems.
                So I am good to go. My only other question is what determines the timeout for saveListEdits methold? I know action java script AJAX lets me determine a timeout setting for each call back, but I don't know where the settings are for built in AJAX methods.

                Thanks again for your prompt replies and guidance. It is much appreciated.

                Comment


                  #9
                  Re: List Control Saving to Server and when primary key is known for new record (Timing issue).

                  This is where Alpha starts to get muddled and fail because the overall process is not well thought through... or is just broken.

                  Here is a property which you can set to a number of milliseconds...

                  Code:
                  {dialog.object}.ajaxCallbackTimeout
                  But... Alpha does not apply this to the List Control callback. In fact, it doesn't seem to be working anywhere.

                  Further, I should be able to do this...

                  Code:
                  {dialog.object}.ajaxCallback('','','callBackTest','','',{ajaxCallbackTimeout: 10000,deviceOfflineFunction: function() {   }});
                  But, this is broken as well... and the ajaxCallbackFailed event fires after about 2 seconds. This is all using the latest pre-release.

                  As you indicate, there seems to be nothing to determine that the List Sync has failed.

                  Is the Ajax Callback Timeout setting working for you?

                  Comment


                    #10
                    Re: List Control Saving to Server and when primary key is known for new record (Timing issue).

                    No, it is not working. It fires in 2 seconds as you stated despite specific AJAX timeout settings over 10 seconds. When I test with poor connection, it will fail 3 or 4 times, then it will succeed. These call backs have very small payloads which should work.
                    Would turning on RAW Http logs uncover any important information?
                    The messages I coded in the ajaxCallbackFailed event are better than the app appearing to be unresponsive.
                    I will put a test UX along with demo to Alpha support to see if they can provide any answers to this situation since I can replicate the problem easily.
                    Thanks again for your help.

                    Comment


                      #11
                      Re: List Control Saving to Server and when primary key is known for new record (Timing issue).

                      Originally posted by Davidk View Post
                      This is where Alpha starts to get muddled and fail because the overall process is not well thought through... or is just broken.

                      Here is a property which you can set to a number of milliseconds...

                      Code:
                      {dialog.object}.ajaxCallbackTimeout
                      But... Alpha does not apply this to the List Control callback. In fact, it doesn't seem to be working anywhere.

                      Further, I should be able to do this...

                      Code:
                      {dialog.object}.ajaxCallback('','','callBackTest','','',{ajaxCallbackTimeout: 10000,deviceOfflineFunction: function() {   }});
                      But, this is broken as well... and the ajaxCallbackFailed event fires after about 2 seconds. This is all using the latest pre-release.

                      As you indicate, there seems to be nothing to determine that the List Sync has failed.

                      Is the Ajax Callback Timeout setting working for you?

                      unfortunately, most of the information in this post here is either flat out wrong or at best misleading

                      a generic ajax callback action allows you to define these events:

                      afterCallbackComplete - fires when the client receives the response from the server
                      ajaxFailed - fires if the client does not receive a request from the server before the specified timeout
                      offLineJavascript - fires if the device does not have a connection (no ajax callback is made)

                      you can see how these events work by building a simple ux that makes an ajax callback to a function that does this:

                      Code:
                      function xb as c (e as p)
                      	
                      	dim sleep as c = request.variables.V.R1.SLEEPDURATION
                      	dim sn as n = val(sleep)
                      	sleep(sn)
                      	xb = "alert('hello from server');"
                      end function
                      there is a control on the ux where you can type in the 'sleepduration' in seconds. this allows you to inject a delay before the server sends a response
                      you can also put a control on the ux where you can set the timeout (in milliseconds) that the client should wait.

                      if you set the sleep duration to (say) 5 - which is 5 seconds, or 5,000 milliseconds
                      and you set the ajaxTimeout to (say) 3,000 milliseconds then when you do an ajax callback, the ajaxFailed event will fire because the server is waiting for 5 seconds before responding, but the client is only allowing a wait of 3 seconds.

                      there is not really any "Alpha Anywhere" code in this. the ajax callback method is a wrapper on the browser's XHR object and we are just setting properties on the XHR object.

                      so it is absolutely not correct to say that these properties are not working. they most definitely are working.

                      with regard to the other comment in this thread about duplicate entries in a sql table if a call to the sync method fails -- AA already anticipates that this can happen -- for example it is possible that at the time the user press the sync button there is a connection, but by the time the server has processed the request and sent a response, there is no connection. so the client never receives the response from the server telling the client to mark the previously dirty records as clean. There is a property in the List builder (Detail View pane) to turn on the sync log. This prevents duplicate CRUD operations from being performed on the server.

                      While the generic ajax callback action in AA does allows you to specify all of the properties discussed above, the {dialog.object}.saveListEdits() method (which calls the ajaxCallback() method) does not currently expose all of the properties of an ajax callback. we will change this so that you can set callback properties in the object passed to the .saveListEdits() method

                      Comment


                        #12
                        Re: List Control Saving to Server and when primary key is known for new record (Timing issue).

                        It looks like {dialog.object}.ajaxCallbackTimeout is valid on some AjaxCallbacks and not others. It's not available for the List Control... which is what is being discussed. We'll have to wait until we trip over another type of Ajax Callback that does not utilize this property. The property should be called {dialog.object}.ajaxCallbackTimeoutExceptForSynchronizingLists.

                        Comment


                          #13
                          Re: List Control Saving to Server and when primary key is known for new record (Timing issue).

                          I don't see how sarcasm contributes to the value of a thread (especially when the content of the posting is actually wrong), but here is the CORRECT statement.

                          Currently, the saveListEdits() method does not expose the ajaxTimeout property, or allow you define handlers for the onAjaxFail event , or the onDeviceOffline event.
                          (I say 'currently' because the next release adds this. However, this is merely a convenience -- it is not adding new functionality that was not already available through other paths).

                          The generic ajaxCallback() method DOES expose these properties.

                          Of course, the saveListEdits() method ultimately calls the ajaxCallback() method to submit the edits, but because the method does not (currently) expose the ajaxTimeout property, the default property is used.
                          Also, since the saveListEdits() method does not (currently) allow you to set the onAjaxFail event handler, the GENERIC event handler is used. This is set in client-side events (see onAjaxCallbackFailed).


                          As the video shows, all of this is working, so your comment about the "{dialog.object}.ajaxCallbackTimeoutExceptForSynchronizingLists" is not actually correct.

                          In the video the Button that does the sync does this:

                          {dialog.object}.ajaxCallbackTimeout = 5000;
                          {dialog.object}.saveListEdits('LIST1',{rows: 'allRows'});

                          In other words, the ajaxCallbackTimeout (generically) is being set to 5 seconds.
                          This means that if the client does not receive a response from the server within 5 seconds, it considers the callback to have failed.
                          (This does not mean that the callback will not ultimately succeed. It just means that the client had not received a response within the allowed time.)

                          Next, we added a server side validation event and in the event we have added:
                          sleep(10)
                          to introduce an artificial 10 second delay before the server sends its response to the client.

                          We are therefore ENSURING that the client will not have received the response within the allowed 5 seconds (as set by the
                          {dialog.object}.ajaxCallbackTimeout = 5000;
                          command in the Sync button's code.)


                          Finally, we have defined the client side onAjaxCallback failed event to display an alert.

                          As the video clearly shows, the alert() is displayed, meaning that the {dialog.object}.ajaxCallbackTimeout is working.


                          Here is the video:
                          https://www.screencast.com/t/XxBZnQPRf

                          Comment


                            #14
                            Re: List Control Saving to Server and when primary key is known for new record (Timing issue).

                            Excellent... very glad that the ajaxCallbackTimeout is now working for List Controls.

                            Comment


                              #15
                              Re: List Control Saving to Server and when primary key is known for new record (Timing issue).

                              Originally posted by Davidk View Post
                              Excellent... very glad that the ajaxCallbackTimeout is now working for List Controls.
                              perhaps I was not clear on this (although I thought I was). I never said it is NOW working for List Controls. It has ALWAYS been working for List controls.

                              Comment

                              Working...
                              X