on 02-07-2019 12:09 PM
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
In the Opportunity InfoProvider they are called
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 filterSub 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
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
92 | |
11 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.