cancel
Showing results for 
Search instead for 
Did you mean: 

How to print a invoice in silent mode

Former Member
0 Kudos

Dear Developers,

I would like to know how can I push the OK button on Printing windows dialog after SBO_Application.ActivateMenuItem ("520") in code. I'm working on a alternative printing wizard and need help on it.

Thank you in advance.

Cheers,

Nghia

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Nghia,

Please note, you can automatically print invoices when you add them (there is a customizing option when you press the add button you can print out the invoice) our you can use document printing wizard.

This stuff is not easy, but try the following:

Logic:

You should implement a multi-threaded program, which is looking for the operating system actual window, and compares with the SAP B1 Window ID. If differs, then you can send an enter key. (click on default button).

You can build up thread safe procedure with custom code, but i have used there a timer, which starts when you send the printing, and stops when enter has been sent.

Add the following code to your addon variables declare section:

Private Declare Function GetForegroundWindow Lib "user32.dll" () As IntPtr
  Dim _timer As New System.Timers.Timer
  Dim lCurHwnd As Integer

When you activating the Print Menu, add the following code

' SAP B1 Window ID via Windows API Call
        lCurHwnd = GetForegroundWindow()
        _timer.Interval = 100
        AddHandler _timer.Elapsed, New System.Timers.ElapsedEventHandler(AddressOf Me.Timer1_Elapsed)

        _timer.Enabled = True
        'RockAndRoll
        SBO_Application.ActivateMenuItem("520")

Now impement the timer eventhandler (thread safe, you can send any keys like ENTER which closes the print dialog box and ESC when you would like to cancel

Private Sub Timer1_Elapsed(ByVal sender As System.Object, ByVal e As System.Timers.ElapsedEventArgs)

        Dim lHwnd As Integer = GetForegroundWindow
        If lCurHwnd = lHwnd Then Exit Sub
        ' Send enter key to Commit the dialog window
        System.Windows.Forms.SendKeys.SendWait("{ENTER}")
        'Stop timer
        _timer.Enabled = False
    End Sub

Regards,

J

Former Member
0 Kudos

Dear János,

Thank you very much for the pretty nice source code. It's worked, I was be able to implement into my documents batch reprinting wizards.

Best Regards,

Nghia

Answers (0)