Alpha Video Training
Results 1 to 3 of 3

Thread: Using page variables in an xbasic callback in a UX

  1. #1
    Member richardurban's Avatar
    Real Name
    Richard Urban
    Join Date
    Apr 2000
    Location
    Harpers Ferry, WV
    Posts
    438

    Default Using page variables in an xbasic callback in a UX

    I have a UX component that makes an xbasic callback. A page variable is used as an argument. I can display the page variable on the a5w page where the UX component is, and in a field on the UX by making the default value = pageVariable.department. However, after many attempts, I cannot get request.variables to read the variable in the xbasic script Am I missing something basic?
    Here is the code to get the variable:
    Code:
    dim Request.Variables.department as c
    if variable_exists("Request.Variables.department")then
    	department=alltrim(Request.Variables.department)
    end if
    I have also tried different variations, like
    Code:
    dim department as c
    if variable_exists("Request.Variables.department")then
    	department=alltrim(Request.Variables.department)
    end if
    The page variable is not retrieved; the value of department is blank, even though the page variable is there.

    I also tried to set an argument in the UX to get its value from the page variable, but I could not figure out how to use that argument in my script, either. What would be the right way to refer to this value in an xbasic call back?
    Last edited by richardurban; 12-25-2014 at 01:06 AM.
    Richard Urban

    Grocery Delivery Software for Stores and Entrepreneurs: http://www.urbangrocery.com

  2. #2
    "Certified" Alphaholic mikeallenbrown's Avatar
    Real Name
    Mike Brown
    Join Date
    Nov 2009
    Location
    United States
    Posts
    1,906

    Default Re: Using page variables in an xbasic callback in a UX

    Not sure if this is the best way of handling it but this should work...

    You said you can make a field equal to the page value. If that's correct then you can use that field as an argument in xbasic. Lets say the field name is "test". Here is how you can use "test" as an argument...

    Code:
    function MyFunctionName as c (e as p)
    
    dim cn as sql::connection
    dim args as sql::arguments
    dim rs as sql::ResultSet
    
    args.set("arg1",e._currentRowDataNew.Test)
    
    cn.Open("::Name::sql")
    
    sqlSelect = "SELECT Field1 FROM MyTableName WHERE Field2 = :arg1"
    
    cn.Execute(sqlSelect,args)
    
    cn.FreeResult()
    cn.close()
    
    end fucntion
    The code above is just an example of course...it doesn't check for errors or do anything with the data.
    Mike Brown - Contact Me
    Programmatic Technologies, LLC
    Programmatic-Technologies.com
    Independent Developer & Consultant

  3. #3
    "Certified" Alphaholic
    Real Name
    David Kates
    Join Date
    Apr 2008
    Location
    Unionville, ON
    Posts
    7,819

    Default Re: Using page variables in an xbasic callback in a UX

    Quote Originally Posted by richardurban View Post
    I have a UX component that makes an xbasic callback. A page variable is used as an argument. I can display the page variable on the a5w page where the UX component is, and in a field on the UX by making the default value = pageVariable.department. However, after many attempts, I cannot get request.variables to read the variable in the xbasic script Am I missing something basic?
    Kind of...

    Request (page) variables set in an a5w page are not available in XBasic Ajax Callbacks.

    They are available in the Server-side onDialogInitialize event. In this event you'd get the Request var and assign it to a State variable. Then that State variable will persist through your code and be available in callbacks.

    From your a5w page you have something like this...

    Code:
    http://phantom:81/AlphaTest/ux_Request_Var_Callback.a5w?id=123
    Which gives you a Request variable with the name of "Id" and a value of 123.

    In your UX onDialogInitialize event you would do something like this...

    Code:
    if variable_exists("request.variables.Id") then
    	e._state.myPageVar = request.variables.Id
    else
    	e._state.myPageVar = "Sorry... No Page Var"
    end if
    And then... in your Callback...

    Code:
    function getPageVar as c (e as p)
    
    dim myPageVar as c = e._state.myPageVar
    
    getPageVar = "alert('my page var is " + myPageVar + "');"
    
    end function

Similar Threads

  1. How to turn page variables into session variables in a grid
    By nlights in forum Application Server Version 11 - Web/Browser Applications
    Replies: 5
    Last Post: 02-25-2013, 12:47 PM
  2. Session Variables Unavailable in Xbasic Events of Grid in Page Layout Component
    By Juniper in forum Application Server Version 11 - Web/Browser Applications
    Replies: 6
    Last Post: 05-18-2012, 07:08 PM
  3. Solution for passing variables between client and server in ajax callback!
    By nlights in forum Application Server Version 11 - Web/Browser Applications
    Replies: 2
    Last Post: 01-28-2012, 05:53 PM
  4. xbasic callback
    By Peter.Greulich in forum Application Server Version 10 - Web/Browser Applications
    Replies: 5
    Last Post: 03-13-2010, 04:20 PM
  5. variables in latest callback javascript sample
    By elbert in forum Application Server Version 10 - Web/Browser Applications
    Replies: 7
    Last Post: 02-21-2010, 11:34 PM

Bookmarks

Posting Permissions

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