Disclaimer: This sample calls undocumented code in the add-on. This might break in future releases if we make major code changes.
We do not offer free support for the following sample.
Disclaimer2: This UF will only be able to be executed in the B1 Client. It can't be executed on a UF Schedule by the Server Component.
Scenario:
Sometimes SAP have some limitations around events and menu items. This can lead to errors like "System.Exception: Menu - Cannot activate a disabled menu item [66000-75]".
If you look in the client afterwards the menu item is not disabled. This is due to SAP having an odd flow where the menu item is not unlocked until the event is completed.
As the macro is event driven you are not able to wait for the menu item to be unlocked.
A workaround to this is to run the rest of the macro in a seperate thread.
Doing this have certain limitations:
- The UI will be responsive = The user can change things while the macro is running
- You should store variables in the @STORES before launching the rest of the macro in a thread
- You cannot debug the first part of the macro anymore as this will block the event and SAP will not unlock the menu items
- It might not work at all. This is a case by case test. If it does not work you are unfortunately out of luck :/
Setup:
You will need to split your macro into two parts.
- The first should run during the event and collect the data on the screen into the @STORE variables.
- The second should be launched in a thread and run outside of the event. You should split it from the point where you get the "Menu - Cannot activate a disabled menu item" error.
Sample:
Macro:
Split it into two:
After splitting the macro you need to create a dynamic code UF with the following code:
Replace the "UF-013" with the code of your second macro: "UF-015" in my case.
Add a new line to your first macro that call the dynamic code that will then call the second part of the macro:
The second macro will now be run in a thread.
Dynamic code for copy/paste:
(new System.Threading.Thread(() => {
try
{
string universalFunctionToRun = "UF-013";
System.Threading.Thread.Sleep(1000);
UniversalFunctions.Module.ActivateUniversalFunction(SBO.AddonLogic.Addon.AddonData, eventForm, universalFunctionToRun, "Dynamic code");
} catch (Exception e)
{
SBO.UI.Notification.MessageBox("Error running UF: " + e);
}
})).Start();
Comments
1 comment
Thank you Morten. Very useful.
Please sign in to leave a comment.