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

Filter list with state variables

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

  • Filter list with state variables

    Hi all,

    I have been researching state variables, using them over session variables if building a PhoneGap app. I have been able to set a state variable with the userid of my logged in user. I have successfully passed my state variable down two levels by using the onRenderComplete client side events for testing.

    Code:
    var pObj = {dialog.object}.getTopParentObject();
    
    var msg2 = pObj.stateInfo['myvar1'];
    alert('this is your state variable loaded from the top parent'+ ' ' +msg2);
    What I would like to do is set this state variable and use it as an argument, which I can then use as a filter for my SQL statement in a list. Does anyone have any info on requesting the state variable from the top parent UX and save it as an argument that can then be used to filter data by user ids?

  • #2
    Re: Filter list with state variables

    owen1.gif ?

    Your code with small adjustment:
    Code:
    var pObj = {dialog.object}.getTopParentObject();
    
    var yourvar = pObj.stateInfo['myvar1'];
    
    setCookie('userid',yourvar,1)
    In JavaScript functions:
    Code:
    function setCookie(cname,cvalue,exdays)
    {
    var d = new Date();
    d.setTime(d.getTime()+(exdays*24*60*60*1000));
    var expires = "expires="+d.toGMTString();
    document.cookie = cname + "=" + cvalue + "; " + expires;
    }
    Of course you can change the expiration to whatever you'd like.

    From there, there is an option to use a cookie to set an argument inside of your list control.

    Comment


    • #3
      Re: Filter list with state variables

      Interesting.... Thanks for the idea Jinx, never used a cookie as an argument before. Two questions.

      I have revised my code in the OnRenderComplete to match yours

      Code:
      var pObj = {dialog.object}.getTopParentObject();
      var myvar2 = pObj.stateinfo['myvar1'];
      setCookie('userid', myvar2, 1)
      and placed this into javascript functions

      Code:
      function setCookie(cname,cvalue,exdays)
      {
      var d = new Date();
      d.setTime(d.getTime()+(exdays*24*60*60*1000));
      var expires = "expires="+d.toGMTString();
      document.cookie = cname + "=" + cvalue + "; " + expires;
      }

      I then created a new argument called myId, variable = userid (Cookie) and then used this argument in my SQL filter. The list comes back blank when run. I tried moving the first bit of code to the OnInitialize event of the list, which did not work either.


      The second question, by using a cookie in a PhoneGap app with an expiration time, essentially be the same as a session variable. Both of which can expire on the user?

      Comment


      • #4
        Re: Filter list with state variables

        James,
        Although I use cookies for other things in my application, I haven't actually tried them in this way yet. I just noticed you can use a cookie inside the list as an argument so I decided to reply to your post with that as a suggestion.

        Add some more code to your functions:

        Code:
        function getCookie(cname)
        {
        var name = cname + "=";
        var ca = document.cookie.split(';');
        for(var i=0; i<ca.length; i++) 
          {
          var c = ca[i].trim();
          if (c.indexOf(name)==0) return c.substring(name.length,c.length);
        }
        return "";
        }
        Now you should be able to test and make sure the value is getting in there.

        Code:
        var test = getCookie('userid');
        alert(test);
        I guess you could also call this function "getCookieValue" as that is what it's supposed to be doing.

        Also, try changing the name of the cookie. I've found that Alpha sometimes doesn't like names like userid and usergroup (maybe they cause a conflict?). Maybe use CookieUID or something.

        As far as expiration. You can make a persistent cookie or make it expire whenever you want. The cookie is stored on the users device so it shouldn't go away....at least until the expiration (if set) or the user clears their cookies.

        Comment


        • #5
          Re: Filter list with state variables

          Jinx,

          You were right about the variable name, I changed it to CookieUID, and then placed the "alert(test);" on a button, when clicked it reports the id value passed from the parent. It also filtered my SQL statement correctly. The wired thing however, when I logout and log back in as a different user, I get an alert with the new userid, but the list is still filtered by the old id value. If I go back one panel and back to the list, the list is then rerendered with the correct userid data.

          Do I need to delete the cookie when logging out?

          Thanks again for the help Jinx

          Comment


          • #6
            Re: Filter list with state variables

            When you say you logged out you mean just out of your application right? The cookies are stored in the browser so it would keep that cookie unless you make it expire or change it. I don't think you can actually delete it for security reasons? I'm pretty sure you can set it to null or blank though.

            Not having done this exact thing before, I'm not sure why the list is filtering like that when the test is correct with the new ID. It seems strange though. It could be a timing issue on when the cookie is set vs when it's read. You may want to set the cookie on login (attach the setcookie javascript to the login component) and not in the list UX if you aren't already doing that.
            Last edited by -Jinx-; 03-22-2017, 06:26 PM.

            Comment


            • #7
              Re: Filter list with state variables

              One of the easiest ways to do this is to add a Textbox control (which you can hide) to your child UX. Then base your child UX List on an argument that gets it's value at run-time... from the Textbox control. You set the value of the Textbox control using the .setValue() method... after you use the code you've posted for the state var.

              Code:
              var pObj = {dialog.Object}.getTopParentObject();
              var stateCustId = pObj.stateInfo['currCustId'];
              {dialog.Object}.setValue('textFilter',stateCustId);
              {dialog.object}.refreshListData('LISTCHILD');

              Comment


              • #8
                Re: Filter list with state variables

                Hi Jinx,

                I successfully changed the cookie on logout, and moved the create cookie to the onLogin event, unfortunately, the issue persisted. Thank you for the help with the cookie idea, I will be using that method in one of my other web apps.

                David, I did something similar to your suggestion, but instead of calling the state variable within the list component, i called it in my main menu component, set the value of a text box to my state var, and used that as an argument to pass into my child UX, this way I didn't have to refresh the list data. Also, by using the state var value in my main menu I have the ability to pass it to all embedded components if needed.

                Thanks guys!

                Comment


                • #9
                  Re: Filter list with state variables

                  Yup... sounds good... lots of ways to get this stuff done. Alpha makes it easy to reach out and pass data around.

                  Comment


                  • #10
                    Re: Filter list with state variables

                    When using State variables you have to make sure they are always available at the point where you need them. There was a case that I reported to Alpha where a component (don't recall if it was UX or Grid) did not initialize state variables early enough when loading on the client when the state vars were being populated from the server. I just made sure my code would not crash if the state variable did not exist yet. I'm not sure if Alpha corrected this behavior or not.

                    When dealing with filtering on UX's I usually just pass Arguments from one UX to the next using AA's built-in Arguments mechanism, even if the Arguments are really only meant for a grandchild UX and/or even if the Argument is meant for a something other than the main SQL statement of the component. Both the client and server-side code have good methods for retrieving the Arguments in a UX. Although, I wonder if component cacheing might mess up arguments, such that an argument retains its original value when a cached component is re-opened. I always turn component cacheing off, as it has messed me up too many times in the past. The other thing to note is that Grids are not so well designed to handle Arguments, or if they are designed to handle Arguments as nicely as UX's then it sure has not been made obvious how to do it.

                    Comment

                    Working...
                    X