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

Help with code - AJAX Callback? Arguments?

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

    Help with code - AJAX Callback? Arguments?

    Working on xbasic script to conditionally update a date field based on another field in the table.

    Currently getting an error with the ajax callback (but I'm sure there are other errors present) stating that "List not found:Contributions" though this is the code generated by Alpha and I have verified that the spelling and capitalization of the list name is correct.

    I would highly appreciate another set of eyes to help me sort out my issues. I'm certain I've got something amiss, particularly in the realm of e.datasubmitted (still don't quite understand it). Xbasic newbie here (and great thanks to madtowng for getting me to my current knowledge level!).

    Here's my Javascript function (got the code from a forum post I found here):
    Code:
    var id_number = {Dialog.object}.getValue('list::Contributions::id_number');
    {dialog.object}.ajaxCallback('','','updatePledge','','_id_number='+id_number);
    And my xbasic:
    Code:
    function updatePledge as c (e as p)
    debug(1)
    'Dim the SQL connection variables
    dim cn as SQL::Connection
    dim ti as SQL::TableInfo
    dim sqlUpdate as c
    dim argsUpdate as SQL::Arguments
    dim itsOpen as L
    dim sqlCode as p
    dim itWorked as L
    dim donorArray[0] as p
    dim dothething as L
    
    'Test for open connection
    itsOpen=cn.open("::name::donor sql")
    
    sqlCode.getData = <<%txt%
    SELECT gift_amount,date_posted,type_contr,depositno,id_number,frequency
    FROM pledgers
    WHERE date_posted = :DATE AND depositno = :DEPOSITNUMBER AND id_number = :id_number
    ORDER BY dateposted
    
    %txt%
    
    'Dim the SQL query variables
    dim id_number as n
    id_number = e._id_number
    dim depositno as c
    depositno = e.datasubmitted.depositno
    dim date_posted as t
    date_posted = time("yyyy-MM-dd",convert_type(e.datasubmitted.date,"D"))
    
    
    itWorked = cn.ToPropertyArray(sqlCode.getData,argsUpdate,donorArray)
    
    for each donor in donorArray
    'Set the arguments for the SQL update query
    argsUpdate.set("date_posted",time("yyyy-MM-dd",convert_type(e.datasubmitted.date,"D")))
    argsUpdate.set("depositno",e.datasubmitted.depositno)
    argsUpdate.set("donorid",e._id_number)
    
    if *any(donor.type_contr,"Pledge") then
    
    dim frequencydays as n
    frequencydays = if(donor.frequency = "Monthly",31,if(donor.frequency= "Quarterly",91,if(donor.frequency = "Every 2 Mnt",61,if(donor.frequency = "Bi-annualy",183,if(donor.frequency="Annually",365,"")))))
    
    dim updatedpledgedate as t
    updatedpledgedate = *add_days(dateposted,frequencydays)
    
    'Define the SQL UPDATE query
    sqlUpdate = "UPDATE pledgers SET NextPledgeDue = "+updatedpledgedate+" WHERE ID_number = :id_number"
    
    dothething = cn.Execute(sqlUpdate,argsUpdate)
    
    if .not. dothething then
    ui_msg_box("Error",cn.CallResult.text)
    else
    
    end if
    end if
    next
    cn.close(cn)
    
    updatePledge =""
    
    end function

    #2
    I don't have the time for a complete review. But:

    1) You should not show your connection string in public. Use "MyConnectionsStringName" or something like that instead.

    2) the ui_msg_box (and any other ui_* functions) won't work in a web app. They're probably not fatal, but still need something else.

    3) Your long if statement is difficult. You might consider the SELECT..CASE..END SELECT method.
    -Steve
    sigpic

    Comment


      #3
      Based on the error, the problem is with your javascript, not with the xbasic. It is either not running the xbasic at all or running it without a proper value for id_number.

      The list not found contribution is referencing this code:

      var id_number = {Dialog.object}.getValue('list::Contributions::id_number');

      You might be better off setting the contributions list to the value of id_number. (In the data source table, set the return value to the id_number or to the key value if id_number is the primary key.)

      Then you can just use {Dialog.object}.getValue('Contributions');

      OR, just use e.datasubmitted.contributions inside your xbasic and don't pass it in as a variable at all.

      Comment


        #4
        lgrupido, Your suggestions seem to have fixed my issue regarding the initial error. Decided to follow your last suggestion and just use e.datasubmitted.contributions in xbasic (once I changed the return value of the list to id_number). How might I call other data from the list? ex: the list has a field depositno (character) that I need to pull as an argument, but i'm not sure how to refer to it.

        Comment


          #5
          Generally, what I do is take advantage of the lists detail view.

          If you setup a detail view for the list and create controls for each field in the detail view to go in, then you can access any value you want using e.datasubmitted because when you click on the row you want, the fields will populate automatically.

          OR

          If you don't want to use the detail view, or you are using it for something else that makes this difficult, you already have the key value of the field. You can simply use a sql call in xbasic to get whatever data you want from the table or any related tables.



          Comment


            #6
            I kept the adjustments to a minimum, and I think I documented the reason for moving code.
            You should be able to reference any field submitted as e.datasubmitted.<field name> (replace <fieldname> with the name of the field).

            If I'm seeing what I think I'm seeing, you should be able to set this up as a trigger in mySQL.
            Let me know how things go and if you need more assistance.


            Code:
            function updatePledge as c (e as p)
            debug(1)
            'Dim the SQL connection variables
            dim cn as SQL::Connection
            dim ti as SQL::TableInfo
            dim sqlUpdate as c
            dim argsUpdate as SQL::Arguments
            dim itsOpen as L
            dim sqlCode as p
            dim itWorked as L
            dim donorArray[0] as p
            dim dothething as L
            
            'Test for open connection
            itsOpen=cn.open("::name::donor sql")
            
            sqlCode.getData = <<%txt%
            SELECT gift_amount,date_posted,type_contr,depositno,id_number,frequency
            FROM pledgers
            WHERE date_posted = :DATE AND depositno = :DEPOSITNUMBER AND id_number = :id_number
            ORDER BY dateposted
            
            %txt%
            
            'Dim the SQL query variables
            dim id_number as n
            id_number = e._id_number
            dim depositno as c
            depositno = e.datasubmitted.depositno
            dim date_posted as t
            date_posted = time("yyyy-MM-dd",convert_type(e.datasubmitted.date,"D"))
            dim frequencydays as n ' moved out of loop
            dim updatedpledgedate as d ' moved out of loop and changed to type D from type T
            'Moved the argsUpdate.set statements to before the query using the args
            'Set the arguments for the SQL update query
            argsUpdate.set("date_posted",time("yyyy-MM-dd",convert_type(e.datasubmitted.date,"D")))
            argsUpdate.set("depositno",e.datasubmitted.depositno)
            argsUpdate.set("donorid",e._id_number)
            itWorked = cn.ToPropertyArray(sqlCode.getData,argsUpdate,donorArray)
            
            for each donor in donorArray
            
            if *any(donor.type_contr,"Pledge") then
            
            'frequencydays = if(donor.frequency = "Monthly",31,if(donor.frequency= "Quarterly",91,if(donor.frequency = "Every 2 Mnt",61,if(donor.frequency = "Bi-annualy",183,if(donor.frequency="Annually",365,"")))))
            select
            case donor.frequency = "Monthly"
            frequencydays = 31
            case donor.frequency = "Quarterly"
            frequencydays = 91
            case donor.frequency = "Every 2 Mnt"
            frequencydays = 61
            case donor.frequency = "Bi-annualy"
            frequencydays = 183
            case donor.frequency = "Annually"
            frequencydays = 365
            end select
            
            updatedpledgedate = *add_days(dateposted,frequencydays)
            
            'Define the SQL UPDATE query
            sqlUpdate = "UPDATE pledgers SET NextPledgeDue = :updatedpledgedate WHERE ID_number = :id_number"
            'Moved the argument setting to after values are set
            
            argsUpdate.Set("updatedpledgedate",time("yyyy-MM-dd",updatedpledgedate))
            
            
            dothething = cn.Execute(sqlUpdate,argsUpdate)
            
            if .not. dothething then
            ui_msg_box("Error",cn.CallResult.text)
            else
            
            end if
            end if
            next
            cn.close(cn)
            Gregg
            https://paiza.io is a great site to test and share sql code

            Comment


              #7
              Originally posted by aprescott View Post
              lgrupido, Your suggestions seem to have fixed my issue regarding the initial error. Decided to follow your last suggestion and just use e.datasubmitted.contributions in xbasic (once I changed the return value of the list to id_number). How might I call other data from the list? ex: the list has a field depositno (character) that I need to pull as an argument, but i'm not sure how to refer to it.
              A little while ago I made a sample component for another developer that demonstrates a couple different ways to get data from a list and into an xbasic function. I hope it is useful to you as well.

              It was created on version 7295. Just import the zipped file.

              Attached Files
              Mike Brown - Contact Me
              Programmatic Technologies, LLC
              Programmatic-Technologies.com
              Independent Developer & Consultant​​

              Comment


                #8
                As I use Viewboxes mostly - my preference is to set state variables in the UX for the client and server side use.

                So in the onClick List events you would say something like this.


                //You can also set a property in the state info object directly (bypassing the .setStateInfo() method)
                //pass the required fields in the currently selected row to the state variables as they can be used
                //in both client and server side functions.

                //------------- state variables ----- -------- current list-----------
                {dialog.object}.stateInfo['_depositno'] = this.selectionData[0].depositno;
                {dialog.object}.stateInfo['_id_number'] = this.selectionData[0].id_number;
                // test the values..
                alert({dialog.object}.stateInfo['_depositno'] + ' ' + {dialog.object}.stateInfo['_id_number'] );


                In the server side xbasic something like this.


                function xb_rundonor as c (e as p)

                debug(1)

                'get the state values set in the onClick List Event the dimmed variables can be any name

                dim _depositno as c = e._state._depositno
                dim _id_number as c = e._state._id_number


                ' what I do as I like the control it gives me, you can manipulate the execution of SQL statement based on values

                dim sql as C = ""

                sql = ""
                sql = sql + "SELECT gift_amount,date_posted,type_contr,depositno,id_number,frequency "
                sql = sql + " FROM pledgers "
                sql = sql + " WHERE date_posted = :DATE AND depositno = '" + _depositno + "' AND id_number = '" + _id_number +"'"
                sql = sql + " ORDER BY dateposted "

                cn.open("::Name::yourdatabasename")
                flag = cn.Execute(sql)



                if flag then ' do something.
                dim rs as sql::ResultSet
                rs = cn.ResultSet
                js = "alert('It worked');"
                else ' don't do anything
                js = "alert('It didn't work');"
                end if

                xb_rundonor = js

                cn.FreeResult()
                cn.close()
                Hope it helps - Pete
                Insanity: doing the same thing over and over again and expecting different results.
                Albert Einstein, (attributed)
                US (German-born) physicist (1879 - 1955)

                Comment


                  #9
                  There's a thought that you let the backend db do the mundane stuff.
                  The process you describe sounds like it's ideal work for the backend.
                  The file attached is a group of tables based on Safersys snapshots
                  of transportation companies.
                  This example shows the creation of multiple tables and triggers.
                  For testing purposes (If you don't want to clutter up your mySQL db,
                  you can paste everything into the mariaDB (interchangeable with mySQL)
                  at https://sqliteonline.com.
                  The specific trigger you are likely to be interested in is the one that sets
                  the value of the taxform based on the value of physicalstate.

                  Feel free to hit me up if you have any questions.
                  Attached Files
                  Gregg
                  https://paiza.io is a great site to test and share sql code

                  Comment

                  Working...
                  X