Alpha Video Training
Results 1 to 26 of 26

Thread: How to run xbasic code upon printing report?

  1. #1
    Member
    Real Name
    Jaime Ben David
    Join Date
    Jan 2011
    Location
    Karkur, Israel
    Posts
    976

    Default How to run xbasic code upon printing report?

    Hi
    In a report (and also needed in a label report) i need to set a Printed field for all the printed records in the report's underlying mysql table to .T. .
    How can i implement that?

    Many thanks
    Jaime

  2. #2
    Member
    Real Name
    Jaime Ben David
    Join Date
    Jan 2011
    Location
    Karkur, Israel
    Posts
    976

    Default Re: How to run xbasic code upon printing report?

    I found the onRecord event in the detail section, and the only sample utilization in the documentation is when using dbf tables as backend. How can i create the update sql in onRecord event when uding a SQL backend?

  3. #3
    Member
    Real Name
    Jaime Ben David
    Join Date
    Jan 2011
    Location
    Karkur, Israel
    Posts
    976

    Default How can i use onRecord report event with mySql?

    I need to use the onRecord detail section event in order to do a simple field update ( set printed = .T. for each printed report ). The sample in the documentation uses dbf tables, anyone knows how to use it with a mySql backend ?

  4. #4
    "Certified" Alphaholic Stan Mathews's Avatar
    Real Name
    Stan Mathews
    Join Date
    Apr 2000
    Location
    Bowling Green, KY
    Posts
    25,119

    Default Re: How can i use onRecord report event with mySql?

    Unless I am missing something...

    SQL::UpdateStatement::Execute()
    There can be only one.

  5. #5
    Member
    Real Name
    Jaime Ben David
    Join Date
    Jan 2011
    Location
    Karkur, Israel
    Posts
    976

    Default Re: How can i use onRecord report event with mySql?

    Thanks for jumping in Stan
    I dont understand.
    I have a report where the underlying table is Orders.
    For each printed record i'd like update to run UPDATE Orders set Printed=1 where ????? ( how can i tell it for currently printing record )?

    Thanks

  6. #6
    Member
    Real Name
    Jaime Ben David
    Join Date
    Jan 2011
    Location
    Karkur, Israel
    Posts
    976

    Default Re: How to run xbasic code upon printing report?

    Here is the only mention of onReport in the documentation ( 2 results in google as well - talk about an obscure feature )
    Code:
    You can use the OnRecord event to update records after they have printed. For example, in an invoicing application, you might have a Status field in the invoice_header table. After you print out invoices, you might want to update this field to say Printed. Here is how you could do this:
    
    t = table.current()
    t.change_begin()
    t.status = "Printed"
    t.change_end(.T.)

  7. #7
    "Certified" Alphaholic Stan Mathews's Avatar
    Real Name
    Stan Mathews
    Join Date
    Apr 2000
    Location
    Bowling Green, KY
    Posts
    25,119

    Default Re: How to run xbasic code upon printing report?

    The example for the suggested function is.

    Code:
    dim conn as SQL::Connection
    dim connString as C
    dim upd as SQL::UpdateStatement
    dim sql_update as C
    connString = "{A5API='Access', FileName='c:\program files\a5v7\mdbfiles\alphasports.mdb'}"
    sql_update = "update customer set bill_city = 'Phoenix', bill_postal_code = '08000', bill_state_region = 'AZ' where customer_id = 1"
    if .not. conn.open(connString) then
        end
    end if
    if .not. upd.parse(sql_update) then
        ui_msg_box("Error", upd.callresult.text)
        end
    end if
    if .not. upd.execute(conn) then
        end
    end if
    So in addition to providing the proper connection string I suppose you need to modify the

    sql_update = "update customer set bill_city = 'Phoenix', bill_postal_code = '08000', bill_state_region = 'AZ' where customer_id = 1"

    line "on the fly".

    something like

    sql_update = "update your_table_name set printed_flag_field = TRUE where record_identifier_field = " +record_identifier_value_of_current_record
    There can be only one.

  8. #8
    Member
    Real Name
    Jaime Ben David
    Join Date
    Jan 2011
    Location
    Karkur, Israel
    Posts
    976

    Default Re: How to run xbasic code upon printing report?

    Assuming i have OrderID as primary key for the table, and in fact it's a printed field as well, my issue is how to refer to i in the onRecord?

    sql_update = "update orders set Printed=TRUE where OrderID = " + ?????????? <--- how do i retrieve the value of current record's OrderID ?

  9. #9
    "Certified" Alphaholic Stan Mathews's Avatar
    Real Name
    Stan Mathews
    Join Date
    Apr 2000
    Location
    Bowling Green, KY
    Posts
    25,119

    Default Re: How to run xbasic code upon printing report?

    sql_update = "update orders set Printed=TRUE where OrderID = " + orders->order_id

    Probably should use

    sql_update = "update orders set Printed=TRUE where OrderID = " + s_quote(orders->order_id)

    to insure data type handling.

    Tested this with a report designed on an active-link table based on the AlphaSports.mdb. Not guaranteeing it will work with MySQL.
    Last edited by Stan Mathews; 10-25-2017 at 02:37 PM.
    There can be only one.

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

    Default Re: How to run xbasic code upon printing report?

    Just curious... why do you need to update on a Report - Per Record Printed basis? E.g. You print 50 records... you're running 50 updates.

    When you run the report... you know the report criteria... is that right? Run the report... and then run the Update based on the same criteria. If it's one record... or 500... in the report... you'll always only run 1 update.

  11. #11
    "Certified" Alphaholic Stan Mathews's Avatar
    Real Name
    Stan Mathews
    Join Date
    Apr 2000
    Location
    Bowling Green, KY
    Posts
    25,119

    Default Re: How to run xbasic code upon printing report?

    For a report based directly on an sql backend it appears the syntax would be

    sql_update = "update orders set Printed=TRUE where OrderID = " + s_quote(sqldatasource->order_id)

    Note: s_quote() may not be appropriate in an sql statement as it inserts double quotes around character values. If the order_id is character the proper usage would be


    sql_update = "update orders set Printed=TRUE where OrderID = '" + sqldatasource->order_id+"'"
    Last edited by Stan Mathews; 10-25-2017 at 03:27 PM.
    There can be only one.

  12. #12
    "Certified" Alphaholic
    Real Name
    Govindan Gandhi
    Join Date
    Aug 2008
    Location
    New York, NY
    Posts
    4,294

    Default Re: How to run xbasic code upon printing report?

    i am curious:
    jaime usually works on web side and asked this question on the browser/mobile section.
    first, the ui_msg_box will not work if and truly this is web side,
    secondly, in web usually the report is created and shown as pdf and then printed, so unlike desktop, the printer is not in direct communication with the report printing mechanism, unless of course there are stuff i do not know. so this onRecord calling an xbasic function may not be suitable in this scenario, if you ask me.

    so the questions will be
    how are you printing your records?
    is this web side or desktop?

    (i know you are using mariaDB.)
    thanks for reading

    gandhi

    version 11 3381 - 4096
    mysql backend
    http://www.alphawebprogramming.blogspot.com
    ggandhi344@gmail.com
    Skype:ggandhi344@gmail.com
    1 914 924 5171

  13. #13
    Member
    Real Name
    Jaime Ben David
    Join Date
    Jan 2011
    Location
    Karkur, Israel
    Posts
    976

    Default Re: How to run xbasic code upon printing report?

    Quote Originally Posted by Davidk View Post
    Just curious... why do you need to update on a Report - Per Record Printed basis? E.g. You print 50 records... you're running 50 updates.

    When you run the report... you know the report criteria... is that right? Run the report... and then run the Update based on the same criteria. If it's one record... or 500... in the report... you'll always only run 1 update.
    Thanks for jumping in
    Indeed i was looking at first for a report event that runs at the end of printing where i could set the Printed field value for all printed records, but found no help in docs how to do this (onPrintExit is the only suitable event i found). The report is run directly from the tabbed_ui and that's why i was looking to run the update from the report.

  14. #14
    Member
    Real Name
    Jaime Ben David
    Join Date
    Jan 2011
    Location
    Karkur, Israel
    Posts
    976

    Default Re: How to run xbasic code upon printing report?

    Quote Originally Posted by GGandhi View Post
    i am curious:
    jaime usually works on web side and asked this question on the browser/mobile section.
    first, the ui_msg_box will not work if and truly this is web side,
    secondly, in web usually the report is created and shown as pdf and then printed, so unlike desktop, the printer is not in direct communication with the report printing mechanism, unless of course there are stuff i do not know. so this onRecord calling an xbasic function may not be suitable in this scenario, if you ask me.

    so the questions will be
    how are you printing your records?
    is this web side or desktop?

    (i know you are using mariaDB.)
    Hi gandhi
    Indeed, as all my apps, this is web side. I am running a report from the tabbed_UI and just need to update a field ( Printed ) to True for all printed records that's all...

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

    Default Re: How to run xbasic code upon printing report?

    In the TabbedUI - Report Button - is that what you're using to run the report? If so, it has a property... "After print Javascript". Run an Ajax Callback in this event... and update.

  16. #16
    "Certified" Alphaholic
    Real Name
    Govindan Gandhi
    Join Date
    Aug 2008
    Location
    New York, NY
    Posts
    4,294

    Default Re: How to run xbasic code upon printing report?

    Quote Originally Posted by WindForce View Post
    Hi gandhi
    Indeed, as all my apps, this is web side. I am running a report from the tabbed_UI and just need to update a field ( Printed ) to True for all printed records that's all...
    okay, good.
    but pressing a button in a place was not in my head when i asked the question ( while that is right answer), i was thinking more in line of filters that will be used in the report, like are they predetermined or at run time?

    since you wanted to know how to harvest the primary id of the records printed in order for you to update ( once primary id is known i am sure you know how to update) telling you to run the ajaxcallback after the report printed won't help if you ask me. you know that already. it is the construction of xbasic function that you need help with.

    if you provide more information that might help or if you have already solved then it is well and good.
    thanks for reading

    gandhi

    version 11 3381 - 4096
    mysql backend
    http://www.alphawebprogramming.blogspot.com
    ggandhi344@gmail.com
    Skype:ggandhi344@gmail.com
    1 914 924 5171

  17. #17
    "Certified" Alphaholic
    Real Name
    Govindan Gandhi
    Join Date
    Aug 2008
    Location
    New York, NY
    Posts
    4,294

    Default Re: How to run xbasic code upon printing report?

    i think you can do this by cheating alpha, let me know if you have not found help elsewhere.
    thanks for reading

    gandhi

    version 11 3381 - 4096
    mysql backend
    http://www.alphawebprogramming.blogspot.com
    ggandhi344@gmail.com
    Skype:ggandhi344@gmail.com
    1 914 924 5171

  18. #18
    Member
    Real Name
    Jaime Ben David
    Join Date
    Jan 2011
    Location
    Karkur, Israel
    Posts
    976

    Default Re: How to run xbasic code upon printing report?

    I still haven't found a solution for this...
    I try to implement David's proposition, but i cannot achieve this part "Run the report... and then run the Update based on the same criteria." How can i refer to the date ranges and other fields the user entered when running the report in the tabbed_ui ?

    Thanks

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

    Default Re: How to run xbasic code upon printing report?

    Where is the user entering date ranges and other fields?

  20. #20
    Member
    Real Name
    Jaime Ben David
    Join Date
    Jan 2011
    Location
    Karkur, Israel
    Posts
    976

    Default Re: How to run xbasic code upon printing report?

    In the tabbed_ui, when you add a button to run a report, you set there the "arguments" to run the report in the properties of the newly created button. That's where it's set...

  21. #21
    Member
    Real Name
    Jaime Ben David
    Join Date
    Jan 2011
    Location
    Karkur, Israel
    Posts
    976

    Default Re: How to run xbasic code upon printing report?

    I think i'm going to create a ux with the fields to run the report, then add a button to run the report. That will give me more control

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

    Default Re: How to run xbasic code upon printing report?

    Yes... it is a bit tough to get an ajax callback going from a tabbed ui. Certainly possible... but then you have to pick up the arguments you're setting... and... if they're available at all, they are buried quite deep.

    An AjaxCallback from a TabbedUI is done like this...

    Code:
    var argRegion = $('b5c81401_a2b3_4715_8620_df6879f72248.PROMPT.REGION').value;
    tbiObj.ajaxCallback('rptUpdate','argRegion='+argRegion);
    https://www.alphasoftware.com/alphaf...I+ajaxCallback

    You can get the guid of the report you're running... and based on that get the arguments from the DOM. The guid for the report is found by inspecting the rendered TabbedUI, and inspecting one of the Arguments Input TextBoxes displayed for the report arguments.

    Setting the additional data parameter of the callback will let you get that data in e.rv of your Xbasic function.

    Running the whole thing from a UX would be much simpler.

  23. #23
    Member
    Real Name
    Jaime Ben David
    Join Date
    Jan 2011
    Location
    Karkur, Israel
    Posts
    976

    Default Re: How to run xbasic code upon printing report?

    Thanks for the insightful lesson David.

    I opted, of course, for the UX course. I entered my fields for the arguments, and added an "embedded object" report set everything and connect the arguments to the fields. It runs correctly.
    Now i would like to set the orders.Printed field value to True for all printed records.
    The report object is set to show on click of a button. Now the onClick javascript event has the following:

    {dialog.object}._functions.runAction_2bf0207b_9237_42c6_87c8_6189693cd3b0(); return false;

    Where/how do i put the ajax callback that will update the db?

  24. #24
    Member
    Real Name
    Jaime Ben David
    Join Date
    Jan 2011
    Location
    Karkur, Israel
    Posts
    976

    Default Re: How to run xbasic code upon printing report?

    ...better yet
    when the click the "run Report" button, the report ( PDF report ) is shown in the placeholder for the report object. Is there someway i could hook the ajax callback that sets the "printed" field to the "Print" button they click in the report preview?

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

    Default Re: How to run xbasic code upon printing report?

    Your Embedded Object Report has a property "After print Javacsript. Put an Ajax Callback in there...

    Code:
    {dialog.Object}.ajaxCallback('','','updateTable','');
    //{dialog.Object}.ajaxCallback('','',xbasicFunction,'' [,additionalData [,optionsObject]]);
    This will call an Xbasic function named "updateTable". The Xbasic function carries the "e" object and so will give you e.dataSubmitted which will hold the UX field values... including your report arguments.

  26. #26
    Member
    Real Name
    Jaime Ben David
    Join Date
    Jan 2011
    Location
    Karkur, Israel
    Posts
    976

    Default Re: How to run xbasic code upon printing report?

    Thanks David, worked perfectly

Similar Threads

  1. xbasic code not returning data - but interactive code does????
    By RobGordon in forum Mobile & Browser Applications
    Replies: 1
    Last Post: 11-25-2014, 07:34 AM
  2. How to convert .java class code to AlphaFive Xbasic code?
    By Suvarchala in forum Application Server Version 11 - Web/Browser Applications
    Replies: 4
    Last Post: 01-04-2012, 12:07 AM
  3. Why inline-javascript code fires before ajax callback UDF xbasic code?
    By eritovs in forum Application Server Version 10 - Web/Browser Applications
    Replies: 6
    Last Post: 10-29-2010, 07:46 AM
  4. xbasic code looping with :Report.saveas gets slower.. and slower..
    By workaholic06 in forum Application Server Version 10 - Web/Browser Applications
    Replies: 5
    Last Post: 03-14-2010, 01:39 PM
  5. Printing Xbasic code jumps of the paper
    By Marcel Kollenaar in forum Alpha Five Version 6
    Replies: 4
    Last Post: 07-30-2004, 11:40 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
  •