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

Thread: Converting Grid Component Code To UX Component Code

  1. #1
    Member
    Real Name
    Steven
    Join Date
    Oct 2011
    Posts
    370

    Default Converting Grid Component Code To UX Component Code

    I am trying to convert code used it a grid component to UX component. Below is the code, that I put in Inline-Javascript. The code should when a video is clicked read the count in a database field add 1 and update the database field with the new count. It should also update a date field with the date that a video was clicked on. The video that the user clicks on is in a List Control so I assume I put the code in on-click event within the List Control.

    var rowNum = {dialog.RowNumber};
    var currCnt = {dialog.Object}.getValue('G','COUNT',rowNum);
    var currDate = new Date();
    var strCurrDate = currDate.toFormat("yyyy/MM/dd");
    {dialog.Object}.setValue('G','DATEVIEWED',rowNum,strCurrDate);
    currCnt = parseInt(currCnt);
    currCnt = (isNaN(currCnt) ? 0 : currCnt);
    currCnt += 1;
    {dialog.Object}.setValue('G','COUNT',rowNum,currCnt);
    {dialog.Object}.submitGridPartRow(rowNum);

  2. #2
    Member
    Real Name
    Steven
    Join Date
    Oct 2011
    Posts
    370

    Default Re: Converting Grid Component Code To UX Component Code

    Any idea on how I would update the code?

  3. #3
    Member
    Real Name
    Steven
    Join Date
    Oct 2011
    Posts
    370

    Default Re: Converting Grid Component Code To UX Component Code

    I have this XBasic code below to update the count and date in a database table. Not sure how to get ID (primary key) for the current row that was clicked on in the list control. I am assuming after getting that I can put that in args.set("currentid", ) and currentid will hold the current row number? Hope this makes sense!

    function updateCount as v (e as p)

    dim globalcn as sql::connection
    dim sql as c
    dim newCount as n
    dim args as sql::arguments
    dim flag as l


    flag = globalcn.open("::name::database")
    args.set("currentid", );
    args.set("date",now())
    newCount = sql_lookup("::name::database", "table", "id = :currentid", "count", args)
    newCount = newCount + 1
    flag = globalcn.execute("UPDATE table SET COUNT = :newCount, DATEVIEWED = :date where id = :currentid")

    end function

  4. #4
    Moderator
    Real Name
    James A. Talbott, Jr.
    Join Date
    Apr 2000
    Location
    Versailles, KY
    Posts
    1,289

    Default Re: Converting Grid Component Code To UX Component Code

    If the list returns the id (either as a field or as the primary key) you can use the on select event of the list, fire the Xbasic script as an AJAX callback, and pass the id to the callback.
    Jay Talbott
    Lexington, KY


  5. #5
    Member
    Real Name
    Steven
    Join Date
    Oct 2011
    Posts
    370

    Default Re: Converting Grid Component Code To UX Component Code

    What code would I put in to pass the id to the callback?

  6. #6
    Moderator
    Real Name
    James A. Talbott, Jr.
    Join Date
    Apr 2000
    Location
    Versailles, KY
    Posts
    1,289

    Default Re: Converting Grid Component Code To UX Component Code

    Code like this could be put on your onSelect of the list:
    var currentID = {dialog.object}.getValue("LIST1");
    {dialog.object}.ajaxCallback('','','updateCount','_currentID='+currentID);
    Then in your Xbasic AJAX callback, the value of the argument would be set like this:
    args.set("currentid", val(e._currentID));
    If you are not getting the results you want, put an alert as the second line of the javascript:
    alert(currentID);
    and put a debug(1) in your Xbasic AJAX callback.

    Hope this helps.
    Jay Talbott
    Lexington, KY


  7. #7
    Member
    Real Name
    Steven
    Join Date
    Oct 2011
    Posts
    370

    Default Re: Converting Grid Component Code To UX Component Code

    Its saying that e._currentID subelement is not found. Is there another name that Alpha stores it instead of e._currentID?

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

    Default Re: Converting Grid Component Code To UX Component Code

    You'd have to post the code you're running in the List onClick event... and the XBasic code you're running. Although the code Jay posted is correct, an assumption that your code is correct can't be made.

  9. #9
    Member
    Real Name
    Steven
    Join Date
    Oct 2011
    Posts
    370

    Default Re: Converting Grid Component Code To UX Component Code

    Sorry I had the ajax callback code in both on select and on click events. The error is not showing anymore but its not updating, when I put in the alert(currentID); code it shows the url string used for the video to play instead of the row id. Not sure why its picking up the url instead of the id.

    Here is the code in the on select event:
    var currentID = {dialog.object}.getValue("FUNNYPETVIDEOS");
    alert(currentID);
    {dialog.object}.ajaxCallback('','','updateCount','_currentID='+currentID);

    Here is the code in the XBasic functions:

    function updateCount as v (e as p)

    dim globalcn as sql::connection
    dim sql as c
    dim newCount as n
    dim args as sql::arguments
    dim flag as l


    flag = globalcn.open("::name::connectionname")
    args.set("currentid", val(e._currentID));
    args.set("date",now())
    newCount = sql_lookup("::name::connectioname", "table", "id = :currentid", "count", args)
    newCount = newCount + 1
    flag = globalcn.execute("UPDATE table SET COUNT = :newCount, DATEVIEWED = :date where id = :currentid")

    end function

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

    Default Re: Converting Grid Component Code To UX Component Code

    It's picking up the URL because of 2 reasons: 1. You probably have the URL set as the Return Value in your List Data Source tab. 2. When you use .getValue() on a List Control, it returns whatever you have set in the Return Value.

    Because you're running Javascript from one of the List Events (you don't confirm which) you don't need to go and get the full List Object using .getValue(). You're already inside the List Object and have full access to the value you want. Also... upon testing... Jay's code isn't quite right for the ajaxCallback... he's missing an empty parameter.

    Code:
    var currentID = this.selectionData[0].CUSTOMER_ID;
    {dialog.Object}.ajaxCallback('','','myListId','','_currentID='+currentID);
    Assuming your List is NOT set up for multiple selection, then this code will get the currently selected List row... and get the value for the column CUSTOMER_ID. Replace CUSTOMER_ID with whatever your key column name is. Then run the callback passing in the currentID to your Xbasic code. Note the empty parameter after the XBasic function name being called.

  11. #11
    Member
    Real Name
    Steven
    Join Date
    Oct 2011
    Posts
    370

    Default Re: Converting Grid Component Code To UX Component Code

    With code, {dialog.Object}.ajaxCallback('','','myListId','','_currentID='+currentID);

    Saying function 'FUNNYPETVIDEOS' not recognized. The variable name of my list control is 'FUNNYPETVIDEOS'. Should it be something else?

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

    Default Re: Converting Grid Component Code To UX Component Code

    I was posting my code... which works for me. You just need to substitute your stuff... the name of your XBasic function...

    {dialog.Object}.ajaxCallback('','','updateCount','','_currentID='+currentID);

  13. #13
    Member
    Real Name
    Steven
    Join Date
    Oct 2011
    Posts
    370

    Default Re: Converting Grid Component Code To UX Component Code

    Ok made that change. Seems the count is getting assigned the correct count but it isn't updating the database table. Here is the update code I have:

    flag = globalcn.execute("UPDATE pvv_funny_pet_videos SET COUNT = :newCount, DATEVIEWED = :date, where id = :currentid",args)
    flag = globalcn.Execute(sql, args)

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

    Default Re: Converting Grid Component Code To UX Component Code

    You're missing args.set("newCount",newCount)

    Just an aside... I always find it dangerous to use keywords for other purposes... or the same name for several items... you never know when they're going to bite back.

    e.g. args.set("date",now()) , args.set("newCount",newCount), COUNT

    I would do this...

    args.set("argDate",now())
    args.set("argNewCount",newCount)
    Using "COUNT" as a database field name is asking for trouble... and isn't descriptive. Count of what? e.g. watchedCount, videoCount

    Also, you should learn to use the XBasic debugger... extremely powerful.
    https://www.ajaxvideotutorials.com/V...unningApps.swf

    Running debug(1), and with globalcn.Callresult set in the Debug Expression, you would have seen this error message...
    One or more argument values were referenced in the SQL query, but were not found in the argument list

    And... why are you calling .execute... and .Execute. .Execute with an empty "sql" variable? You're calling .execute twice.
    And... your Update statement is wrong... you have a comma after :date.
    Last edited by Davidk; 11-11-2017 at 07:40 PM.

  15. #15
    Member
    Real Name
    Steven
    Join Date
    Oct 2011
    Posts
    370

    Default Re: Converting Grid Component Code To UX Component Code

    Still isn't updating database table, this is what I have:

    function updateCount as v (e as p)
    debug(1)
    dim globalcn as sql::connection
    dim sql as c
    dim args as sql::arguments
    dim flag as l
    dim newCount as n


    flag = globalcn.open("::name::connection")
    args.set("currentid", val(e._currentID))
    args.set("argDate",now())
    args.set("argNewCount",newCount)
    argNewCount = sql_lookup("::name::connection", "pvv_funny_pet_videos", "id = :currentid", "count", args)
    argNewCount = argNewCount + 1
    flag = globalcn.execute("UPDATE pvv_funny_pet_videos SET COUNT = :argNewCount, DATEVIEWED = :argDate, where id = :currentid",args)
    flag = globalcn.Execute(sql, args)
    end function

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

    Default Re: Converting Grid Component Code To UX Component Code

    Check my comments above... I added some...

    Code:
    flag = globalcn.open("::name::connection")
    
    args.set("currentid", val(e._currentID))
    args.set("argDate",now())
    args.set("argNewCount",newCount)
    
    argNewCount = sql_lookup("::name::connection", "pvv_funny_pet_videos", "id = :currentid", "count", args)
    argNewCount = argNewCount + 1
    
    flag = globalcn.execute("UPDATE pvv_funny_pet_videos SET COUNT = :argNewCount, DATEVIEWED = :argDate WHERE id = :currentid",args)

    One more thing... I wouldn't structure my code this way. You're creating 2 connections to the server... one on your sql_lookup... and another in globalcn.open... way too much work.

    Just use globalcn.open and execute one sql statement...

    flag = globalcn.execute("UPDATE pvv_funny_pet_videos SET COUNT = COUNT + 1, DATEVIEWED = :date where pvCommentId = :currentid",args)
    No need to go and get the COUNT if you're just going to increase it by 1... let sql do that for you. Your code would be...

    Code:
    flag = globalcn.open("::name::connection")
    args.set("currentid", val(e._currentID)); 
    args.set("date",now()) 
    flag = globalcn.execute("UPDATE pvv_funny_pet_videos SET COUNT = COUNT + 1, DATEVIEWED = :date where pvCommentId = :currentid",args)
    Last edited by Davidk; 11-11-2017 at 07:54 PM.

  17. #17
    Member
    Real Name
    Steven
    Join Date
    Oct 2011
    Posts
    370

    Default Re: Converting Grid Component Code To UX Component Code

    Almost there, but it is setting the count to 0 for some reason instead of getting the count and adding one. When I debug it argNewCount has the correct count but 0 is getting put into database field for some reason. Here is the code:

    function updateCount as v (e as p)

    dim globalcn as sql::connection
    dim sql as c
    dim args as sql::arguments
    dim flag as l
    dim newCount as n


    flag = globalcn.open("::name::connection")
    args.set("currentid", val(e._currentID))
    args.set("argDate",now())
    args.set("argNewCount",newCount)

    argNewCount = sql_lookup("::name::connection", "pvv_funny_pet_videos", "id = :currentid", "count", args)
    argNewCount = argNewCount + 1


    flag = globalcn.execute("UPDATE pvv_funny_pet_videos SET COUNT = :argNewCount, DATEVIEWED = :argDate WHERE id = :currentid",args)
    end function

  18. #18
    Member
    Real Name
    Steven
    Join Date
    Oct 2011
    Posts
    370

    Default Re: Converting Grid Component Code To UX Component Code

    Sorry, I re-read what you said and here is the code I have but it isn't updating the count in the database field, it leaves it the same. Here is the code:

    function updateCount as v (e as p)

    dim globalcn as sql::connection
    dim sql as c
    dim args as sql::arguments
    dim flag as l


    flag = globalcn.open("::name::petvv")
    args.set("currentid", val(e._currentID))
    args.set("argDate",now())


    flag = globalcn.execute("UPDATE pvv_funny_pet_videos SET COUNT = COUNT + 1, DATEVIEWED = :date where id = :currentid",args)
    end function

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

    Default Re: Converting Grid Component Code To UX Component Code

    You've no idea how helpful the debugger is. This is what it reports...
    One or more argument values were referenced in the SQL query, but were not found in the argument list
    So... I know the problem is with the arguments... and... here is what you have...

    argDate... :date

    The problem with the code you were running with newArgCount is that you were setting the value of the argument... and then trying to add 1 to the argument. It doesn't work that way.

    Code:
    newCount = sql_lookup("::name::connection", "pvv_funny_pet_videos", "id = :currentid", "count", args)
    newCount = newCount + 1
    args.set("argNewCount",newCount)
    Now you can use argNewCount... and it's value is the new count. However, increasing the value in the sql statement is better.

Similar Threads

  1. Code to open detail tab pane in grid component
    By Jane1234 in forum Mobile & Browser Applications
    Replies: 4
    Last Post: 05-26-2015, 11:58 AM
  2. UX component from QR code using http get
    By bh1981 in forum Mobile & Browser Applications
    Replies: 2
    Last Post: 10-04-2013, 04:07 AM
  3. Link Component to A5W Code
    By SSwart in forum Application Server Version 10 - Web/Browser Applications
    Replies: 0
    Last Post: 02-06-2012, 05:04 PM
  4. Insert Grid Component Code not firing....
    By omagarc in forum Application Server Version 10 - Web/Browser Applications
    Replies: 6
    Last Post: 07-27-2011, 12:24 AM
  5. Insert Grid Component Code not firing....
    By omagarc in forum Alpha Five Version 10 - Desktop Applications
    Replies: 1
    Last Post: 07-22-2011, 07:07 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
  •