Friday, February 1, 2013

Posting multiple batches with a macro

In a recent forum post, a GP user wanted to use a macro to post multiple batches using the Purchasing Batch Entry window. Sounds easy enough, but wait!

The macro worked fine for posting a single batch, but when the second batch was added, the macro always failed. The reason for the failure is that a Progress window pops up each time you post a Purchasing Batch. The Progress window is shown below:

progress window

In order to solve this problem, you need to account for the opening of this window in your macro. When you record a macro during posting, the macro system does not record it correctly. Below is a comparison of the right way and the way the macro system records it.

The RIGHT way:
NewActiveWin dictionary 'default'  form 'Progress_Control' window 'Progress_Window'

The WRONG way:
ActivateWindow dictionary 'default'  form 'Progress_Control' window 'Progress_Window'

The complete macro to post two batches in a row is below.

Until next post!
 
Here’s the macro.

Each command should be on a single line, it should not wrap.

CommandExec dictionary 'default' form 'Command_Purchasing' command 'POP_Batch_Entry'
NewActiveWin dictionary 'default' form 'POP_Batch_Entry' window 'POP_Batch_Entry'


#!BATCH POSTING 1

NewActiveWin dictionary 'default' form 'POP_Batch_Entry' window 'POP_Batch_Entry'
ActivateWindow dictionary 'default' form 'POP_Batch_Entry' window 'POP_Batch_Entry'
TypeTo field 'Batch Number' , 'BATCH_NUMBER_1'
  MoveTo field Origin item 0
  ClickHit field Origin item 1 # 'Receivings Trx Entry'
MoveTo field 'Batch Comment'
  MoveTo field 'Post Button'
  ClickHit field 'Post Button'
NewActiveWin dictionary 'default'  form 'Progress_Control' window 'Progress_Window'
NewActiveWin dictionary 'default'  form 'POP_Batch_Entry' window 'POP_Batch_Entry'


#!BATCH POSTING 2

TypeTo field 'Batch Number' , 'BATCH_NUMBER_2'
  MoveTo field Origin item 0
  ClickHit field Origin item 1 # 'Receivings Trx Entry'
MoveTo field 'Batch Comment'
  MoveTo field 'Post Button'
  ClickHit field 'Post Button'
NewActiveWin dictionary 'default'  form 'Progress_Control' window 'Progress_Window'
NewActiveWin dictionary 'default'  form 'POP_Batch_Entry' window 'POP_Batch_Entry'


#!CLOSE AND END

CloseWindow dictionary 'default' form 'POP_Batch_Entry' window 'POP_Batch_Entry'
NewActiveWin dictionary 'default' form sheLL window sheLL
CommandExec form BuiLtin command cmdQuitApplication