Alpha DevCon 2018
Results 1 to 12 of 12

Thread: UX List's custom Control (column) - to access UX control in xbasic/server

  1. #1
    Member
    Real Name
    mkpatil
    Join Date
    Jul 2013
    Posts
    198

    Default UX List's custom Control (column) - to access UX control in xbasic/server

    In UX List I have added a custom Control (column) shown below. This on the List Builder > Fields Tab (second tab)/properties.
    It needs to access the value of field in the UX component [say {dialog.object}.getValue('text1') - this is on client side, but need to access the text1 on server]

    I tried e.text1, Request.Variables.V.R1.text1 and also tmpl.text1, but with no success. How do I access this?
    I debugged the tmpl, but could not see this control on it. Help.

    function CUSTOM_ITEM1_render as c (ds as p, tmpl as p)
    'Specify the Xbasic that returns the HTML for this control.
    'This function must return CUSTOM_ITEM1_render, which should
    'contain the HTML that will be displayed.
    'The 'ds' argument that is passed in contains the current
    'values for each of the fields in the current List row.
    'For example: ds.data("Firstname")

    '-------------------------------------------------------------------
    on error goto CUSTOM_ITEM1_xbasicError

    'Write Xbasic code here that returns the HTML to be displayed by this control

    CUSTOM_ITEM1_render = ds.data("col1") + ds.data("col2") + tmpl.text1

    end
    CUSTOM_ITEM1_xbasicError:
    CUSTOM_ITEM1_render = "Error in custom control xbasic: " + error_text_get()
    end function
    Regards!

  2. #2
    "Certified" Alphaholic Clipper87's Avatar
    Real Name
    Frank
    Join Date
    Dec 2008
    Location
    Antwerp, Belgium
    Posts
    1,891

    Default Re: UX List's custom Control (column) - to access UX control in xbasic/server

    Maybe you can do everything client side & save a roundtrip to the server ? See this video http://www.ajaxvideotutorials.com/V1...clientside.swf
    Frank

    Tell me and I'll forget; show me and I may remember; involve me and I'll understand

  3. #3
    Member
    Real Name
    mkpatil
    Join Date
    Jul 2013
    Posts
    198

    Default Re: UX List's custom Control (column) - to access UX control in xbasic/server

    Frank. Thanks. I needed this column from server as there are other calculations that are need to be on server side, therefore I chose server side computed column. (sorry, did not mention this in my first post).

    If unable to access complete e object can I access state variables created in JS shown below on server xbasic. How to access that?

    {dialog.object}.setStateInfo({MyField1: 'myvalue1'});

    Regards!

  4. #4
    "Certified" Alphaholic Clipper87's Avatar
    Real Name
    Frank
    Join Date
    Dec 2008
    Location
    Antwerp, Belgium
    Posts
    1,891

    Default Re: UX List's custom Control (column) - to access UX control in xbasic/server

    Frank

    Tell me and I'll forget; show me and I may remember; involve me and I'll understand

  5. #5
    Member
    Real Name
    mkpatil
    Join Date
    Jul 2013
    Posts
    198

    Default Re: UX List's custom Control (column) - to access UX control in xbasic/server

    Thank you Frank.
    UX List's custom Control (column) seems to not have access to the 'e' object or even state variables. It is very strange that the server logic is not able to access this. tmpl that is the component, that it has access and the row elements using ds.data(...) - that's it.
    Hopefully, there is a way to access that. Meanwhile, I have a workaround where I am saving the values I need into a temp table and accessing the values from the same table in the above.

    Can anyone please confirm that the UX LIST's server side computed column's xbasic logic does not have access to the 'e' object and therefore cannot read the value of any other control (fields) or data elements on the UX, other than just the values in the current rows of the list.

    Regards!

  6. #6
    Alpha Software Employee Selwyn Rabins's Avatar
    Real Name
    Selwyn Rabins
    Join Date
    Mar 2000
    Location
    Boston, MA
    Posts
    5,264

    Default Re: UX List's custom Control (column) - to access UX control in xbasic/server

    if the list is being rendered on the initial render of the ux, then it would be meaningless to expect access to the value of controls or of the state variables.

    however, if the list is being rendered on an ajax callback (for example, if the user clicked a button to refresh the list), then your xbasic can reference 'request.variables'. this will have all of the variables that are submitted when the request is made. this will include the value in all controls on the UX and the state variables. so while the 'e' object is not passed to the xbasic, you can still likely find what you want in 'request.variables'.

  7. #7
    Member
    Real Name
    mkpatil
    Join Date
    Jul 2013
    Posts
    198

    Default Re: UX List's custom Control (column) - to access UX control in xbasic/server

    Thank you so much. Request.Variables.V.R1.text1 works now.

    After reading your post, the concept is clearer now. Request.Variables.V.R1.text1 did not work before, because the list was been populated during the initial rendering of list and was referring this object [Request.Variables.V.R1.text1] that did not exist during the initialization. This was not required. Changing the 'Delay populate List till active search' on the List builder properties search Tab now avoids the errors that I was getting.

    Regards!

  8. #8
    Member
    Real Name
    Michael Cornford
    Join Date
    Oct 2011
    Location
    East Sussex, UK
    Posts
    884

    Default Re: UX List's custom Control (column) - to access UX control in xbasic/server

    We have this piece of code that works in development. It works on the server in the office.

    It does not work when deployed to a server in the UK.

    We have uninstalled Alpha and reinstalled the webserver, all to no avail.

    Is there anything else we can try?


    function xsaved as c (e as p)


    dim conn as SQL::Connection

    conn.open("::Name::MySQL_Daybook")




    sql_insert1 = "insert into transactions (`Bank Account`, `In`, `Out`, Date, `Nominal Code`, Type, Description, Pounds) values (:a_Save_Bank_Acc, :a_Save_In, :a_Save_Out, :a_Save_Date, :a_Save_Nominal, :a_Save_Type, :a_Save_Description, :a_Save_Pounds)"


    dim args as sql::arguments

    args.add("a_Save_Bank_Acc", request.variables.v.r1.Save_Bank_Acc)
    args.add("a_Save_In", request.variables.v.r1.Save_In )
    args.add("a_Save_Out", request.variables.v.r1.Save_Out)
    args.add("a_Save_Type", request.variables.v.r1.Save_Type )
    args.add("a_Save_Date", request.variables.v.r1.Save_Date)
    args.add("a_Save_Nominal", request.variables.v.r1.Save_Nominal )
    args.add("a_Save_Description", request.variables.v.r1.Save_Description)
    args.add("a_Sav e_Pounds", request.variables.v.r1.Save_Pounds)


    ? conn.execute(sql_insert1,args) = .T.


    end function

  9. #9
    Alpha Software Employee Selwyn Rabins's Avatar
    Real Name
    Selwyn Rabins
    Join Date
    Mar 2000
    Location
    Boston, MA
    Posts
    5,264

    Default Re: UX List's custom Control (column) - to access UX control in xbasic/server

    are you sure that the connection string 'MySQL_Daybook' is not defined on your server. check the a5_connection.a5i file on your server.

    also, i see that your code does not have any error reporting in it. this is not a best practice.

    for example, you should be doing

    dim flag as l
    flag = cn.open("your named connection string")
    if flag = .f. then
    ? "Error. Could not open connection. Error reported was" + cn.callresult.text
    exit function

  10. #10
    Member
    Real Name
    Michael Cornford
    Join Date
    Oct 2011
    Location
    East Sussex, UK
    Posts
    884

    Default Re: UX List's custom Control (column) - to access UX control in xbasic/server

    When we hard code with values it works perfectly.

    args.add("a_Save_Bank_Acc", 1) etc.

    We can update the database in Navicat and Alpha.

  11. #11
    Alpha Software Employee Selwyn Rabins's Avatar
    Real Name
    Selwyn Rabins
    Join Date
    Mar 2000
    Location
    Boston, MA
    Posts
    5,264

    Default Re: UX List's custom Control (column) - to access UX control in xbasic/server

    here is what you say is working:

    Code:
    args.add("a_Save_Bank_Acc", 1)


    here is what you say it not working:

    Code:
    args.add("a_Save_Bank_Acc", request.variables.v.r1.Save_Bank_Acc)

    it is clear why the pattern that is not working is not working.

    in the case that is working you are setting the a_Save_Bank_Acc to a NUMERIC value.

    in the case that is not working you are setting the sargument to a STRING value.
    (becuase all variables in a web app that are submitted to a server are string - in Alpha Anywhere, PHP, ASP.NET or any other technology)

    so the argument is the wrong data type.
    if your code reported back when there were errors, then you would have seen the error message,

    you need to change your code to convert the value to a number.

    e.g.

    Code:
    args.add("a_Save_Bank_Acc", convert_type( request.variables.v.r1.Save_Bank_Acc, "N") )

  12. #12
    Member
    Real Name
    Michael Cornford
    Join Date
    Oct 2011
    Location
    East Sussex, UK
    Posts
    884

    Default Re: UX List's custom Control (column) - to access UX control in xbasic/server

    Thanks Selwyn

    This works ... will add error checking before we go to production.

    function xxxsave as c (e as p)



    dim conn as SQL::Connection

    conn.open("::Name::MySQL_Daybook")




    sql_insert1 = "insert into transactions (`Bank Account`, `In`, `Out`, Date, `Nominal Code`, Type, Description, Pounds) values (:a_Save_Bank_Acc, :a_Save_In, :a_Save_Out, :a_Save_Date, :a_Save_Nominal, :a_Save_Type, :a_Save_Description, :a_Save_Pounds)"


    dim args as sql::arguments

    args.add("a_Save_Bank_Acc",convert_type(request.variables.v.r1.Save_Bank_Acc, "N"))
    args.add("a_Save_In", convert_type(request.variables.v.r1.Save_In, "N" ))
    args.add("a_Save_Out", convert_type(request.variables.v.r1.Save_Out, "N"))
    args.add("a_Save_Type", request.variables.v.r1.Save_Type )
    args.add("a_Save_Date", convert_type(request.variables.v.r1.Save_Date , "D"))
    args.add("a_Save_Nominal", request.variables.v.r1.Save_Nominal )
    args.add("a_Save_Description", request.variables.v.r1.Save_Description)
    args.add("a_Save_Pounds", convert_type(request.variables.v.r1.Save_Pounds, "N"))



    ? conn.execute(sql_insert1,args) = .T.

    end function

    One interesting point is that it worked in house in the incorrect format. It was only by transferring it to another development machine and editing that we produced a working edition on the server.

    Michael

    P.S. Alpha's help and response on the message board is awesome, everything was my fault and inexperience but still people jump in to help.

    Thank You.

Similar Threads

  1. List control with custom data source and parent list
    By sjackson@drake in forum Mobile & Browser Applications
    Replies: 1
    Last Post: 07-01-2015, 09:26 PM
  2. List control custom control
    By PhilM1965 in forum Mobile & Browser Applications
    Replies: 5
    Last Post: 08-30-2013, 06:55 PM
  3. A custom control that can access the data on a form using javascript.
    By irwincohen in forum Application Server Version 9 - Web/Browser Applications
    Replies: 13
    Last Post: 04-09-2013, 12:03 PM
  4. Custom Control - META Tag managed as part of the custom control?
    By CarlMPearson in forum Application Server Version 11 - Web/Browser Applications
    Replies: 0
    Last Post: 10-15-2011, 07:24 PM
  5. Access custom control value in validate events
    By DOntquIT in forum Alpha Five Version 9 - Desktop Applications
    Replies: 4
    Last Post: 09-04-2008, 05:35 AM

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
  •