Get a Jumpstart with our Sample Apps
Results 1 to 19 of 19

Thread: List Control - action javascript - how to define session variables

  1. #1
    Member
    Real Name
    javier
    Join Date
    Jul 2012
    Location
    Madrid
    Posts
    147

    Default List Control - action javascript - how to define session variables

    Hi,

    I´m now replacing some of my grids with list controls and I don´t know how to get round to the following:

    In a list control I have inserted a button into each row that the list renders, and then define a javascript action for each button. This will open another UX component and I need to define a session variable at that time, with specific information from the row.

    So far, when using a grid I did as follows:

    Action Javascript -> Open a UX component -> Override settings -> Set session variables
    and then I define the session variable that I want to pass on to the UX component:

    SV_codigo = {javascript}function(rowNum) { return {grid.object}.getValue('G','symbol_alt',rowNum); }(rowNum)


    But this does not seem to work the same way on a list control.

    My question is: How can I define this session variable in the list control?

    thanks,
    javier

  2. #2
    "Certified" Alphaholic
    Real Name
    David Kates
    Join Date
    Apr 2008
    Location
    Unionville, ON
    Posts
    6,382

    Default Re: List Control - action javascript - how to define session variables

    Javier,

    I'd like to ask why you need a session variable in the UX component that you are opening from the List control? What are you doing in the UX that you need a session var?

  3. #3
    Member
    Real Name
    javier
    Join Date
    Jul 2012
    Location
    Madrid
    Posts
    147

    Default Re: List Control - action javascript - how to define session variables

    Quote Originally Posted by Davidk View Post
    Javier,

    I'd like to ask why you need a session variable in the UX component that you are opening from the List control? What are you doing in the UX that you need a session var?
    Thanks David.

    From any row in the list control, if I press the buttom I would like to open another UX component (ajax callback) where I pass on 2 sessions variables:

    First, I show the name of the item in a text box control:

    session.SV_nombre

    Second, I define an argument to filter a SQL select statement:

    dim sqlArgs as sql::arguments
    sqlArgs.set("newCodigo",session.SV_codigo)




    Javier

  4. #4
    "Certified" Alphaholic
    Real Name
    David Kates
    Join Date
    Apr 2008
    Location
    Unionville, ON
    Posts
    6,382

    Default Re: List Control - action javascript - how to define session variables

    You don't need to use session vars in this case. You can stay in the client and define a Dialog Namespace Object and assign that object properties which are your variables.

    In your first UX, define and set the namespace object...

    Code:
    {dialog.Object}.appVars = {};
    {dialog.Object}.appVars._nombre = 123;
    {dialog.Object}.appVars._codigo = "abc";
    EDIT: This is now corrected... as Rich points out we are working with Parent/Child

    In your second UX, possibly in the Client side event onRenderComplete, access your Parent UX and the vars object in that parent and grab those variables...

    Put one into your textbox control...

    Code:
    var pObj = {dialog.Object}.getParentObject();
    {dialog.Object}.setValue('nameTextbox',pObj.appVars._nombre);
    Do the same for Codigo, but hide that textbox control.

    Then, in your xbasic routine... access that control value with e.datasubmitted.
    Last edited by Davidk; 08-11-2014 at 10:45 PM.

  5. #5
    Member
    Real Name
    Rich Fulham
    Join Date
    May 2011
    Location
    Portland, OR
    Posts
    747

    Default Re: List Control - action javascript - how to define session variables

    The following line for the second UX does not work in in a test that I did:

    {dialog.Object}.setValue('nameTextbox',{dialog.Object}.appVars._nombre);

    The second occurrence of "dialog.object" needs to refer to the first ux.

    So, this is what worked for me in my test of the second UX:

    var o = {dialog.Object}.getParentObject();
    dialog.Object}.setValue('nameTextbox', o.appVars._nombre);

  6. #6
    "Certified" Alphaholic
    Real Name
    David Kates
    Join Date
    Apr 2008
    Location
    Unionville, ON
    Posts
    6,382

    Default Re: List Control - action javascript - how to define session variables

    Yes... I forgot we were dealing with Parent/Child objects. Thanks Rich.

    It may still be easier/more straight forward to set namespace variables in the parent UX. But... actually... once you're in the child UX, you can get the parent object, and access the controls directly... no need to create variables in the first place.
    Last edited by Davidk; 08-11-2014 at 10:46 PM.

  7. #7
    Member
    Real Name
    Rich Fulham
    Join Date
    May 2011
    Location
    Portland, OR
    Posts
    747

    Default Re: List Control - action javascript - how to define session variables

    I have been using "Arguments" for passing variables. The "Arguments" do not have to be used or consumed in the SQL statement; they can be used for other things. I'm not too happy with that method, though, as it works differently for UXs and Grids and Alpha seems to be missing some built-in functions to handle it cleanly.

  8. #8
    Member
    Real Name
    javier
    Join Date
    Jul 2012
    Location
    Madrid
    Posts
    147

    Default Re: List Control - action javascript - how to define session variables

    Hello David and Rich,
    I tried your suggestions and it works nicely.
    Thanks so much for your help!!!
    All the best,
    Javier

  9. #9
    Member
    Real Name
    Jim DeWitt
    Join Date
    Jun 2014
    Posts
    50

    Default Re: List Control - action javascript - how to define session variables

    David, I have two list controls in a UX and want to open the same Embedded UX passing a Company ID field from either one, can this be done without setting a session variable?

  10. #10
    "Certified" Alphaholic
    Real Name
    David Kates
    Join Date
    Apr 2008
    Location
    Unionville, ON
    Posts
    6,382

    Default Re: List Control - action javascript - how to define session variables

    You don't need to pass a variable into your embedded UX. Since it's embedded, it's a child. So, use the .getParentObject() method in the embedded UX (as above) to get a pointer to the parent. Then you can get the value of either list control using that parent object. Let me know if you need an example.

  11. #11
    Member
    Real Name
    Jim DeWitt
    Join Date
    Jun 2014
    Posts
    50

    Default Re: List Control - action javascript - how to define session variables

    thanks David, right now I have the embedded UX opening with an Argument, my problem is it only works for one list so I'd like to learn how to do it with getParent like you said, just having a little trouble getting it, here goes:

    1. I have List1 and List2, both return a CompanyID.
    2. I have an embedded UX with an OrdersList and a some fields above it for CompanyName and Phone
    3. What would the getParent statement look like and where would it go? Can it populate the list and the CompanyName/Phone fields?

  12. #12
    "Certified" Alphaholic
    Real Name
    David Kates
    Join Date
    Apr 2008
    Location
    Unionville, ON
    Posts
    6,382

    Default Re: List Control - action javascript - how to define session variables

    I think you're right in the concept of passing data to the child instead of what I suggested... it's easier.

    List1 and List2 will get the embedded child UX and set a value into a hidden control on the child.
    The embedded UX List will filter based on an argument which looks at that hidden control.

    You can also perform a ._filterList method on the embedded UX List.

    This shows you how to do both processes.

    http://www.youtube.com/watch?v=UT54K851bE0

  13. #13
    Member
    Real Name
    Rich Fulham
    Join Date
    May 2011
    Location
    Portland, OR
    Posts
    747

    Default Re: List Control - action javascript - how to define session variables

    Jim,
    If you are working with embedded components then David has a great solution.
    In the case where you open the components in different windows or tabbed-UI panes then I thought I'd mention that sometime ago I posted this the solution that I use for passing arguments between grids and UX's. But as I mentioned above, I'm not completely happy with it.

    When you have multiple instances of the same component open then you have to be very careful about any JavaScript that you have added to your component. "JavaScript" functions declared in one instance of your component may get overwritten by another instance. This creates quite a problem if you have placeholders in your JS. You also have to consider if the Alpha JavaScript Library will use a cached version of the component or request a new copy of it from the server. It would be best to look at old threads or start another thread for these issues.
    Last edited by RichCPT; 08-23-2014 at 07:55 PM.

  14. #14
    Member
    Real Name
    Jim DeWitt
    Join Date
    Jun 2014
    Posts
    50

    Default Re: List Control - action javascript - how to define session variables

    David that looks perfect, it is however kicking my ass lol, I tried both your methods but I cant get the Company ID to pass through. The embedded UX has the hidden field and argument tied to it, if I change the default value of the hidden field (called it "cid") the preview changes accordingly. Code below is in the on click event of the list in the parent ux which is returning the CompanyID field and opening the embedded UX that has the orders list:

    var cObj = {dialog.Object}.getChildObject('ORDERS2','ux');
    cObj.setValue('cid',this.value);
    cObj.refreshListData('Orders');

    Any Ideas?

  15. #15
    "Certified" Alphaholic
    Real Name
    David Kates
    Join Date
    Apr 2008
    Location
    Unionville, ON
    Posts
    6,382

    Default Re: List Control - action javascript - how to define session variables

    Jim,

    You write that you're opening the embedded UX. It's usually our language that messes us up. If the UX is embedded... then you're not opening it... right?

    So... 'ORDERS2' is your embedded UX Alias - as defined in the embedded control on the parent.

    Unhide cid on the child ux... for testing.

    Does the value of cid change when you click on a parent List row?

  16. #16
    Member
    Real Name
    Jim DeWitt
    Join Date
    Jun 2014
    Posts
    50

    Default Re: List Control - action javascript - how to define session variables

    Thanks again David, understood, you're right it is embedded and Orders2 is the alias. I got it working and discovered some things...

    1. I had to move the hidden "cid" control out of the panel that contained the list.
    2. I was using Action javascript with "inline javascript" to run your code then "panel actions" to open the panel. Changed this to all text javascript like the demo you sent.

    After testing it seems both these things prevent the "cid" field from populating.

    So it works, huge thanks...but there is a lag when you go back and forth choosing items in the list testing on an iPhone, preview is faster so not noticeable.

    When the embedded UX is displayed the previous choice is visible while it updates, is there a way to shorten the lag or clear the embedded UX before it displays, maybe a time delay? (I'm running local sql on windows 7)

  17. #17
    "Certified" Alphaholic
    Real Name
    David Kates
    Join Date
    Apr 2008
    Location
    Unionville, ON
    Posts
    6,382

    Default Re: List Control - action javascript - how to define session variables

    Jim,

    Your item # 1 has me wondering... do you have a panelcard around your List control... in the UX which is embedded? The hidden control belongs to the child UX. And, unless you have a reason for using a panelcard here, you don't need one. The panelcards only need to be used in the parent UX.

    Item # 2 makes sense (that it wouldn't work) because this.value is no longer valid for the List control. Instead, you need to use .getValue to get the value of the List control.

    I don't see the previous choices... the lag... they may be there but it's updating so fast I can't really tell.

    Running the code directly is definitely a bit faster than going through Actions.

    And I would probably go with the "filter" method instead of a hidden field... it's cleaner.

    Here's an example of using Action Javascript compared with using javacsript directly.

    http://www.youtube.com/watch?v=y9qzAwJWmzQ

  18. #18
    Member
    Real Name
    Jim DeWitt
    Join Date
    Jun 2014
    Posts
    50

    Default Re: List Control - action javascript - how to define session variables

    Great video David, thanks again... I stripped down the ux I'm embedding, took out all the panel cards and now it's just the list control, using the filter method.

    I have Alpha on a Virtual Box VM running on a Mac, I publish the app, view it in safari on the mac and it runs fast, on the iPhone over the wifi it lags, when I let the app sit for a while the lag is very long. Question: I guess it could be my wifi but if the app is running on say Zebra Host and the user has a slow connection will these lags be apparent? I thought a lot of the data was cached in the device browser...

  19. #19
    Member
    Real Name
    javier
    Join Date
    Jul 2012
    Location
    Madrid
    Posts
    147

    Default Re: List Control - action javascript - how to define session variables

    Great video David. Thanks!

Similar Threads

  1. Replies: 1
    Last Post: 06-18-2014, 02:00 PM
  2. Session Variables as Date values in Array? Access Session Variable from Javascript ?
    By kimhere in forum Application Server Version 11 - Web/Browser Applications
    Replies: 3
    Last Post: 04-26-2013, 03:02 PM
  3. how to transfer session.variables between Javascript on HTML-page?
    By René Stout in forum Application Server Version 10 - Web/Browser Applications
    Replies: 5
    Last Post: 05-25-2011, 07:24 AM
  4. JavaScript vs. Session variables
    By Peter.Greulich in forum Archived Wishlist
    Replies: 2
    Last Post: 06-08-2010, 04:27 PM
  5. V10 Can session variables be ref'd in Javascript?
    By ismac in forum Application Server Version 10 - Web/Browser Applications
    Replies: 1
    Last Post: 08-24-2009, 12:52 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •