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

Stop execution of A5.executeThisThenThat

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

    Stop execution of A5.executeThisThenThat

    I have this Javascript

    Code:
    function productLookup() {
    
    {dialog.object}.runAction('LookupProduct');
    }
    
    function resetField() {
    
    {dialog.Object}.setValue('Search1',"");
    }
    
    function addNewRow() {
    
    {dialog.Object}.addRepeatingSectionRow('CONTAINER_3');
    this.value='';
    }
    
    function setNewField() {
    
    var count = {dialog.Object}._getRepeatingSectionRowCount('CONTAINER_3');
    {dialog.Object}.setRepeatingSectionActiveRow('CONTAINER_3',count);
    }
    
    var keyCode = event.charCode || event.keyCode;
    if (keyCode==13) A5.executeThisThenThat(productLookup,resetField,addNewRow,setNewField);
    It's a Point of Sale app.
    ProductLookup() does a Lookup and Fill in Fields from the data entered into the Search field, placing the results into a Repeating Section.
    resetField() just blanks out the Search field ready for the next product lookup
    addNewRow() adds the new row in the Repeating Section for the next product
    setNewField() sets the new row as Active.

    And the A5.executeThisThenThat is triggered by the 'Enter' key. This entire script is in the onKeyPress of the Search field.

    Here's what I want to do. If the product is not found in the productLookup() Lookup and Fill In Fields, I want the entire script to stop with the popup "Item Not Found". I CAN do that with the 'Not Found Action' on the Lookup, but it will continue to run the A5.executeThisThenThat items.

    How do I make it stop running the script if the product is not found?

    #2
    Re: Stop execution of A5.executeThisThenThat

    I'm not sure that you can stop a .executeThisThenThat() method.

    Instead, use A5.runChain. Essentially, they do the same thing... but you can stop A5.runChain.

    https://www.alphasoftware.com/docume...n%20Method.xml

    The doc is, as usual... terrible. The doc does reference both A5.runChain and .executeThisThenThat but they don't bother telling you why they have 2 methods that do essentially the same thing.

    Also, the doc doesn't speak to .stop() very well...

    Let's say, according to the example code in the doc... that you decide to stop the process at "action2". Instead of calling obj.next()... you would call obj.stop().

    Code:
    function action2(obj) {
        console.log('this is a synchronous function');
        var err = "this is my error"
        obj.stop(err);
        //obj.next();
    }
    Now... the sample code has a function for the onStop callback. The sample code assumes this callback is called because of an error... but it really could be anything. So... I'd change it a bit...

    Action2 would be...

    Code:
    function action2(obj) {
        console.log('this is a synchronous function');
        var msg = "this is my message";
        obj.stop(msg);
        //obj.next();
    }
    And the A5.runChain method would be...

    Code:
    A5.runChain(actions,
        function() { alert('alldone'); },
        function(msg) { alert('error: ' + msg); }
    );
    Last edited by Davidk; 04-01-2018, 08:52 PM.

    Comment


      #3
      Re: Stop execution of A5.executeThisThenThat

      Thanks, David. This is very insightful information. Thank you for sharing.

      Comment


        #4
        Re: Stop execution of A5.executeThisThenThat

        Thanks, David. I will definitely look into that. I thought a way to have more control was to put this in one xbasic function. So I used this one. But, how would I enter the part that would stop the script if the SKUTemp field is blank?

        Code:
        function getProductInfo as c (e as p)
        	
        'debug(1)
        
        dim cn AS SQL::Connection
        dim rs AS SQL::ResultSet
        dim args AS SQL::Arguments
        dim productId as n
        dim js as c
        dim sqlStmt as c
        dim flag as l
        dim prodData as c
        
        'get the productId
        productId = e.dataSubmitted.SKUTemp
        
        flag = cn.Open("::Name::SQL")
        if flag = .f. then
        	cn.close()
        	js = "alert('Error Connecting to Database);"
        	getProductInfo = js
        	exit function
        end if	
        
        sqlStmt = "SELECT TaxExempt, Active, quantity, price, tax1, item_id, item_name, SKU FROM Inventory WHERE item_id = :prodId "
        args.set("prodId", productId)
        
        flag = cn.Execute(sqlStmt,args)
        if flag = .f. then
        	cn.close()
        	js = "alert('Error executing query');"
        	getProductInfo = js
        	exit function
        end if
        
        rs = cn.ResultSet
        prodData = rs.ToJSONObjectSyntax()
        
        'pass back a call to a Javascript function... including the product info data... now in JSON format.
        getProductInfo = "processProductData('" + prodData + "');"
        
        cn.close()
        
        end function

        Comment


          #5
          Re: Stop execution of A5.executeThisThenThat

          I feel there's a lot of information missing here. Nonetheless...

          What you're doing with your XBasic function in place is... executing code from the Client... where you have the SKUTemp control... and it's value... empty or not.

          You're making a callback to the Server... accessing SKUTemp... and then testing SKUTemp at the server to see if you should proceed to do something.

          That's like wanting to make a sandwich with rye bread. So you grab the bread box (let's say you have a bread box) and walk to the store. Once you get to the store you open your bread box and find there is a rye bread inside. You say... oh... I don't need to buy a rye bread... I already have one... I'm going home to make a sandwich.

          Why start at the client with a value you already have... and go all the way to the server to test it?

          Comment


            #6
            Re: Stop execution of A5.executeThisThenThat

            Ha! I see your point. Let me rework this...

            Comment


              #7
              Re: Stop execution of A5.executeThisThenThat

              Ok. I put a quick client-side javascript validation. It checks for the existence of a value in the SKUTemp field. If no such value, it's done with an alert. If it DOES have a value, off to the Xbasic script to process the lookup for the product info.

              I still think I'm kinda running back and forth between Javascript and Xbasic, but it's good for now. I'll sleep on it. Thanks for the help!

              Comment


                #8
                Re: Stop execution of A5.executeThisThenThat

                Following this thread, I have two statements that I want to run but not if there is an error
                the first is:
                {dialog.Object}.Submit();

                The second one is this:
                var po = {dialog.Object}.getParentObject();
                po.panelSetActive('LOGIN',true);

                I do not want to run the second action if there are errors in the dialogs fields... would I use the chain function OR is there an easier way to stop the submit if there is an error? Without the second action the submit would return to the panel card and give focus to the field with the error. I do not want to proceed with action 2 unless all is good. Can anyone offer me a quick fix for this?
                NWCOPRO: Nuisance Wildlife Control Software My Application: http://www.nwcopro.com "Without forgetting, we would have no memory at all...now what was I saying?"

                Comment


                  #9
                  Re: Stop execution of A5.executeThisThenThat

                  After almost 6 years of doing this I am surprised at how dumb I can be sometimes. What I was trying to do was stop the submittal of a new user account unless there were no errors with the new user account setup. This was much easier solved with the following in the AfterDialogValidate server side function.
                  Code:
                  dim e.javascript as c
                  if rtc.flagWebSecurityhasGlobalError = .T. then	
                  	e.javascript = e.javascript + "alert('"+rtc.WebSecurityGlobalErrorText+"');"
                  else
                  	'no errors - new account was created you go back to the parent component where the actual login screen is.
                  	'The registration component is an embedded object in a persistent login component.
                  	
                  	dim js_afterNewAccount as c 
                  	js_afterNewAccount = <<%txt%
                  	
                  		var po = {dialog.Object}.getParentObject();
                  		po.panelSetActive('LOGIN',true);
                  	}
                  	%txt%
                  	
                  	e.javascript = e.javascript + ";" + crlf() + js_afterNewAccount
                  	
                  	
                  end if
                  NWCOPRO: Nuisance Wildlife Control Software My Application: http://www.nwcopro.com "Without forgetting, we would have no memory at all...now what was I saying?"

                  Comment


                    #10
                    Re: Stop execution of A5.executeThisThenThat

                    There may be a reason you can't easily do this but what about just doing .runAction('LookupProduct') on the 'Enter' key and inside the LookupProduct Javascript Action run the 3 remaining functions via A5.executeThisThenThat if the conditions you want are met.

                    Comment

                    Working...
                    X