Alpha Video Training
Results 1 to 10 of 10

Thread: Using checkbox select column and filtering with email.

  1. #1
    Member
    Real Name
    Roelof
    Join Date
    Jul 2008
    Location
    Seattle, WA
    Posts
    763

    Default Using checkbox select column and filtering with email.

    I have set up a grid with the checkbox select column, and have added a button, that when people have selected some records by clicking in the check boxes, I can filter and only see the records that customers have selected.

    Question:
    After selected I want to create a button so that people can click on it and a email is send with those selected records in it, (This is a simple inventory program.), to the responsible person.

    Thanks
    Roelof

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

    Default Re: Using checkbox select column and filtering with email.

    I used an Action Button, placed in the Record Navigator/Grid Toolbar to run an Ajax Callback that runs this code.

    I think you'll need to get to the table in code in order to get the specific data for each row that is checked... not sure if you can get to the data directly. At least you have the keys and the rows. There are a few way to get an email message out - a search here will produce several options.

    Code:
    function Email_Recs as c (e as p)
    
    
    dim count as n
    dim emsg as c
    
    emsg = ""
    
    count = val(e.checkboxRows.countChecked)
    if count = 0 then
        dim cmd as c
        cmd = "alert('You did not check any rows');"
        CopyRec = cmd
        exit function
    end if
    dim i as n
    for i = 1 to count
    	emsg = emsg + e.checkboxRows.rows[i] + crlf()
    next i	
    
    dim pm as p
    pm.to = "name@rogers.com"
    pm.to_alias = "David"
    pm.from = "info@company.ca"
    pm.from_alias = "info@company.ca"
    pm.subject = "Grid Records Select Test Email"
    pm.message = emsg
    pm.attachments = ""
    
    email_send2(pm)
    
    
    
    end function

  3. #3
    Member
    Real Name
    Roelof
    Join Date
    Jul 2008
    Location
    Seattle, WA
    Posts
    763

    Default Re: Using checkbox select column and filtering with email.

    I copied the function into a button in the button action, I go into Text mode and copy the function that you gave me.

    I get an error, just clicking on the Working preview.
    It says: An error has occurred in the script on this page.
    Line 1231
    Char 44
    Error Expected '('
    Code 0

    Do you want to continue running scripts on this page.

    I am not a programmer so I don't know what the issue is.
    As soon as I remove the function everything works. I can click on the check box and filter the records.
    But with the code in it it crashes.



    Thanks
    roelof

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

    Default Re: Using checkbox select column and filtering with email.

    This function needs to go into the grid under Properties, Xbasic Function Declarations.
    Then, in your button, add an Action Javascript, Ajax Callback, and put the name of the function (Email_Recs, if you kept the same name) into the function name, and without the parens ().

  5. #5
    Member
    Real Name
    Roelof
    Join Date
    Jul 2008
    Location
    Seattle, WA
    Posts
    763

    Default Re: Using checkbox select column and filtering with email.

    This is what I am getting at this point. I have followed your instructions but this is what comes up when I push the button:
    "Error executing Ajax callback function 'Email_Recs'. Error reported was: Function: 'Email_Recs' was not recognized "
    Sorry this does work I put it in the wrong box, I guess I did not follow your instructions.

    The only thing I get back is :
    1
    2

    So how do I get the record and the information in the record back?
    Last edited by Atta; 06-01-2011 at 11:52 AM.

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

    Default Re: Using checkbox select column and filtering with email.

    Yes, the only information being emailed in this example are the selected record row #'s. The attached images might help confirmed what goes where.

    To get the actual data from each record I think you have to open the associated table using xbasic and read the data from there. I'm not sure if there is a way to loop through the selected rows and get data from each row... have to look into that. Are you using SQL or DBF tables?
    Attached Images Attached Images

  7. #7
    Member
    Real Name
    Roelof
    Join Date
    Jul 2008
    Location
    Seattle, WA
    Posts
    763

    Default Re: Using checkbox select column and filtering with email.

    Than you VERY much for that information. I got it to work like the pictures above. I am working now on getting the information in the email. I am using SQL

  8. #8
    Member
    Real Name
    Roelof
    Join Date
    Jul 2008
    Location
    Seattle, WA
    Posts
    763

    Default Re: Using checkbox select column and filtering with email.

    So I have found out that the records that it "filters" it stores the record# from my SQL table in e.checkedRows.key1...

    See picture:currentrow.JPG

    How can I get to that record in a loop, I cannot type e.checkedRows.key1[I]

    Because then the next step is that the record is e.checkedRows.key2[I] etc.

    So this works e.checkedRows.key1[i] but the next step through the loop is ARRAY INDEX OUT OF BOUNDS
    I hope this makes sense. If not please let me know.

    dim i as n
    for i = 1 to count
    emsg = emsg + e.checkboxRows.rows[i] + e.checkedRows.key[i]:[i] + crlf()
    next i

    Anybody can give me some pointers?

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

    Default Re: Using checkbox select column and filtering with email.

    I believe you need to go after the SQL table in order to get to the data in the rows selected. If it's just one row, then you'd have the variables for the current row available, but multiple rows will need a select statement. Here's some code that grabs the selects rows and selects from the table and builds a message.

    Code:
    function Email_Recs as c (e as p)
    
    dim count as n
    dim emsg as c
    dim conn as SQL::Connection
    dim args as SQL::Arguments 
    dim rs as SQL::ResultSet
    dim count as n
    dim sql as c
    
    emsg = ""
    
    count = val(e.checkboxRows.countChecked)
    if count = 0 then
        dim cmd as c
        cmd = "alert('You did not check any rows');"
        Email_Recs = cmd
        exit function
    end if
    
    'Build the Arguments set to pass in SQL stmt.
    dim i as n
    for i = 1 to count
    	args.set("PKValue_R" + i + "_1", eval("e.checkedRows.key" + i + "[1]"))
    next i	
    
    sql = "SELECT * FROM tblProducts WHERE " + e.checkboxFilter 
    
    if conn.Open("::Name::Connection","admin","PW") then
    	 conn.PortableSQLEnabled = .f.
    	 if conn.execute(sql,args) then
    	 	rs = conn.ResultSet
                   conn.close()
         else
             'could not execute redrirect to error
           	  Email_Recs = "alert('Execution Problem');"
              conn.close()
              end
         end if
    else
         Email_Recs = "alert('Connection Problem');"
         end
    end if
    
    while rs.NextRow()
      emsg = emsg + rs.data("ProdId") + " " 
    end while
    
    dim pm as p
    pm.to = "name@rogers.com"
    pm.to_alias = "David"
    pm.from = "info@website.ca"
    pm.from_alias = "info@website.ca"
    pm.subject = "Grid Records Select Test Email"
    pm.message = emsg
    pm.attachments = ""
    
    email_send2(pm)
    
    end function

  10. #10
    Member
    Real Name
    Roelof
    Join Date
    Jul 2008
    Location
    Seattle, WA
    Posts
    763

    Default Re: Using checkbox select column and filtering with email.

    Thank you very much for this, how can I put in here that the customers email opens up with the information, ready to be send?
    Because if I email it to me, then I do not know who needs it, or from whom it is coming. (I do not use security)

    You are using
    while rs.NextRow()
    emsg = emsg + rs.data("Itemname"+"Qty") + crlf()
    end while

    With the above statement it comes up with an error, ( I have added the Qty)

    In the xbasic but where is the rs.data, and how can I put more variables behind it.
    When I click in the debugger on the RS it comes up with a whole lot of items, but the data has nothing?
    Last edited by Atta; 06-04-2011 at 10:54 PM. Reason: updated

Similar Threads

  1. Checkbox select column
    By gaby_h in forum Application Server Version 10 - Web/Browser Applications
    Replies: 10
    Last Post: 11-12-2014, 01:29 PM
  2. Select ALL Checkbox
    By erichf in forum Application Server Version 10 - Web/Browser Applications
    Replies: 4
    Last Post: 10-11-2010, 06:25 PM
  3. checkbox select column placement
    By christappan in forum Application Server Version 10 - Web/Browser Applications
    Replies: 0
    Last Post: 10-11-2010, 12:55 PM
  4. Adding Select All to Checkbox Dialog Box
    By thebside in forum Alpha Five Version 7
    Replies: 2
    Last Post: 01-03-2007, 11:44 AM
  5. Select checkbox in WAS
    By Peter.Greulich in forum Archived Wishlist
    Replies: 2
    Last Post: 07-07-2006, 01:54 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
  •