cancel
Showing results for 
Search instead for 
Did you mean: 

Callback_AfterRedisplay not working in Analysis for Office Workbook

stefan_rottwinkel
Discoverer

Hi everyone, I have created an Analysis for Office Report which contains different datasources from 2 InfoProviders (CRM activities and opportunities). Unfortunately in the activity InfoProvider the Characterics are called

  • 0BPARTNER__0SALES_GRP / 0BPARTNER__0SALES_GRP

In the Opportunity InfoProvider they are called

  • 0BP_ACTIVIT_0SALES_GRP / 0BP_ACTIVIT_0SALES_OFF

So when filtering the report to a certain Sales Group or Sales Office I would have to add 2 filters. To avoid this I would like to set one filter via VBA. Under ThisWorkbook I have registered the callbacks

Public Sub Workbook_SAP_Initialize()

' register callbacks
Call Application.Run("SAPExecuteCommand", "RegisterCallback", "AfterRedisplay", "Callback_AfterRedisplay")

End Sub

In Module1 I added the following code to read the values from the activity filter and set it for the opportunity filter

Sub FilterSalesGroup()

Application.ScreenUpdating = False

Worksheets("Queries").Activate

'Select the Variable from Activity Filter

Dim lResult As Long

Dim SlsGrp As String

SlsGrp = Range("C6").Value

Dim SlsOff As String

SlsOff = Range("C5").Value

'Set the SlsGroup variable as filter for the OPP Data Source

lResult = Application.Run("SAPSetFilter", "DS_3", "0BP_ACTIVIT__0SALES_GRP", SlsGrp, "INPUT_STRING")

lResult = Application.Run("SAPSetFilter", "DS_1", "0BP_ACTIVIT__0SALES_GRP", SlsGrp, "INPUT_STRING")

'Set the SlsOff variable as filter for the OPP Data Source

lResult = Application.Run("SAPSetFilter", "DS_3", "0BP_ACTIVIT__0SALES_OFF", SlsOff, "INPUT_STRING")

lResult = Application.Run("SAPSetFilter", "DS_1", "0BP_ACTIVIT__0SALES_OFF", SlsOff, "INPUT_STRING")

Application.ScreenUpdating = True

End Sub

Public Sub Callback_AfterRedisplay()

Call FilterSalesGroup

End Sub

So each time the Sales Group or Sales Office Filter for the Opportunity Data source are set, the Macro should set the same filters for the Opportunity Datasources DS_1 & DS_3.

If I start the Macro FilterSalesGroup manually or from a button within Excel, it works fine. But the Callback_AfterRedisplay method is not working in this workbook, while I use the same framework in another report. Of course we will change the InfoProviders, but I would like to use the VBA procedure as a workaround for the time being.

Is anyone facing the same issues? Any ideas are welcome

Thanks Stefan

former_member523998
Participant

I realize my answer is months later, but curious if this was resolved.

Stephenkraj
Explorer

Hi Stefan,

I too faced the same issue today.

Finally, did a workaround using an Excel function.

Please paste the below code at "Thisworkbook" of your AO workbook

Public Sub Workbook_SAP_Initialize() 
' register callbacks Call Application.Run("SAPExecuteCommand", "RegisterCallback", "AfterRedisplay", "Callback_AfterRedisplay")
Call Application.OnTime(Now, "FilterSalesGroup")
End Sub

Accepted Solutions (0)

Answers (3)

Answers (3)

former_member523998
Participant

Theoretically, your code should work. I tried running something similar by calling a different macro in the Callback_AfterRedisplay (version 2.7). I'm guessing this has to do with the activity of your FilterSalesGroup macro. To test, instead of calling the FilterSalesGroup macro, have it call a simple macro that just says msgbox "This worked". I'm guessing it will run correctly.

I may be wrong, but wouldn't your code create an infinite loop because of your AfterRedDisplay has SAPSetFilter query within it? If this actually worked, wouldn't it keep triggering the AfterRedisplay procedure...? Again, if you commented out these lines of code, perhaps it works.

As a workaround, perhaps have users refresh by pressing a specific button that calls each macro (including refresh) from start to finish?

Curious if you (or anyone) determines if that infinite loops is the issue.

fanaitdev39
Explorer
0 Kudos

i've tried the suggested workaround, but it's still not calling my macro, based on sap api function calls (SapSetFilter is not part of it).

my AFO version is: 2.8.1300.98253

Assigning the macro to a button is a workaround as well, but I'd prefer the Callback_AfterRedisplay approach.

Any suggestions highly appreciated.

Txs.

reyemsaibot
Active Participant
0 Kudos

Hi,

i tried your code on my machine and ran into the same problem, the "normal" code is working but the CallBack doesn't. Maybe it is a problem with the company guide lines for macros? In my company all macros are disabled, so maybe that's the reeason, the Callback cannot be registered.

I am currently on AO 2.7.300.86673

I hope this will help you a little bit.