Conditionally Activate Extensions

Hi All,

Today I want to share with the way how you can enable and disable extensions dynamically.

You know that when you have published extension as a DLL or a Code file it will be automatically discovered by Acumatica Framework and used.
However there is a hidden way to stop Acumatica from usage of that extension. Do do that you just need add static method IsActive() to your extension.

public class GL_Batch_Ext : PXCacheExtension<PX.Objects.GL.Batch>
  {    
      public static bool IsActive()
      {
        return false;
      }
  }

Acumatica will automatically call that method by signature (you need to have correct name, public, static and return bool) and if it returns False, extensions will be ignored.
That works the same way for Graph and Cache extensions.
Also note, that if method rise an exception extension will be loaded any way.

Good thing about it that you really can decide dynamically what extension should be loaded based on database value or current company.So that is a way how you can have different business logic customization for different companies.

So in that example I have renamed one of fields on Journal Entry screen based on current company id:

Have a nice development!

7 Replies to “Conditionally Activate Extensions”

  1. Hi Sergey,
    When is this property checked for the PXGraphExtension? On every page loading or it is checked once and cached?

    1. Samvel, I think after the first evaluation, this property is cached somewhere.
      If you need to clear all information you can try:
      PXDatabase.ResetSlots();
      PXPageCacheUtils.InvalidateCachedPages();
      But please note that clearing of cache will affect performance.

  2. Hello Sergey, I tried this on 2018 R2, very straightforward instruction that were followed, it seems not working.

    1. Hi Ed, this functionality is widely used in Acumatica internally and should be working fine in any version.
      I recommend to double check if there is something wrong. This works only from extensions (cache and graph). Make sure you do not have duplicate extensions. If one in DLL and one in Cust project, they may be different. 2 DLLs also might have different classes.
      Lastly you can put a breakpoint there and debug.

  3. Hi Sergey,
    Thank for your post. I would like to ask is that limitation about version of using this kind of customization? Which version should be use for that?

Leave a Reply

Your email address will not be published. Required fields are marked *