cancel
Showing results for 
Search instead for 
Did you mean: 

Print invoice to a text file

Former Member
0 Kudos

i need to print my invoice to a text file by just pressing the print button.

without any format, is this posible?

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

But that's only if i have acces to de addons, but in the case when i can't modify anything in SAP o Addons and the only thing i can work with is store procedures an views how can i convert an invoice to a text file when a user press the print button?

former_member201110
Active Contributor
0 Kudos

Hi Evelyn,

I don't think you can achieve this without using the UI API (i.e. an add-on) if you want the export to occur when the user clicks on the print button. In theory you can write a stored procedure to export data to a text file but there is no way to trigger this and pass the relevant document number to it unless you capture the print event in the UI API.

If you are looking for a non-development solution then you might have more luck looking for a solution on the reporting forum or on the general consulting forum here on the SDN.

You may be able to achieve this with the Boyum add-on but I'm not sure.

Kind Regards,

Owen

former_member201110
Active Contributor
0 Kudos

Hi Evelyn,

Here's a couple of ways you could tackle this:

1) You can trap the PrintDataEvent in the UI API and get access to the report data, which is exposed as a XML string. You could then use a XmlDocument object (or a similar parser) to read the data and save the fields you want to a file.

Firstly, register the PrintDataEvent in your addon (this needs to go somewhere in your add-on startup procedure)

this._sboApp.ReportDataEvent += new SAPbouiCOM._IApplicationEvents_ReportDataEventEventHandler(this._sboApp_ReportDataEvent);

Then add the print data event to the filters

private void SetEventFilters()
{
    // Create a new EventFilters object
    _sboFilters = new SAPbouiCOM.EventFilters();
    // Add the print event type to the container
    _sboFilter = _sboFilters.Add(SAPbouiCOM.BoEventTypes.et_PRINT_DATA);
    // Set filters
    _sboApp.SetFilter(_sboFilters);
}

Finally, write code to read the xml report data when the report is printed

private void _sboApp_ReportDataEvent(ref SAPbouiCOM.ReportDataInfo eventInfo, out bool BubbleEvent)
{
    BubbleEvent = true;

    if(eventInfo.BeforeAction) 
    {
        // Check to see if the calling form is the correct type
        SAPbouiCOM.Form sboForm = (SAPbouiCOM.Form)_sboApp.Forms.Item(eventInfo.FormUID);

        if (sboForm.TypeEx == "133") // AR Invoice
        {
            // Call RegisterForReport method so the UI API stores the report data and passes to ReportDataEvent when BeforeAction is false
            eventInfo.RegisterForReport(true);
        }
    }
    else
    {
        try
        {
            // Instantiate a XMLDocument to load the report data
            XmlDocument xDoc = new XmlDocument();
            xDoc.LoadXml(eventInfo.GetReportData(1, eventInfo.GetPageCount(), false));

            // Code to loop through the XML document and save it to a text file goes here
        }
        catch (Exception ex)
        {
            _sboApp.SetStatusBarMessage("Error: " + ex.Message, SAPbouiCOM.BoMessageTime.bmt_Medium, true);
        }
    }
}

2) You could read the data directly from the database but this relies on the document already being saved. To do this, trap the event of the user clicking on the print or print preview menus and if the form is in ok mode then read the document numebr and use a recordset object to get the full document data.

Kind Regards,

Owen