Solved

Activate Extension Conditionally doesn't return the expected value

  • 16 November 2022
  • 6 replies
  • 42 views

Userlevel 4
Badge

Hello All,

 

I am trying to activate an extension in APInvoiceEntry conditionally based on a setup extension from PreferencesGeneral. In all methods typically I can pass “Base” as a parameter in my code and retrieve the expected data but in “public static bool IsActive()” when I try to pass the Base (in my case APInvoiceEntry) it is not recognized. As an alternative, I tried to directly select from the database but I am not sure why the setup record is returned null and obviously, I can not get the extension from null. I read @Sergey post “https://asiablog.acumatica.com/2017/02/dynamically-activate-extensions.html” but couldn’t find a solution there either. See my code below and advise how I can overcome this issue.

 

public class HCLAPInvoiceEntry : PXGraphExtension<APInvoiceEntry>
{
public static bool IsActive()
{
PreferencesGeneral setup = PXDatabase.SelectMulti<PreferencesGeneral>() as PreferencesGeneral;
HCLSMPreferencesGeneral setupExt = setup.GetExtension<HCLSMPreferencesGeneral>();

return (setupExt != null) ? setupExt.UsrHCLAPInvoiceApprovalWorkflow == HCLEPWorkflows.EnhancedWorkflow : false;
}
}

 

icon

Best answer by aaghaei 17 November 2022, 01:00

View original

6 replies

Since the IsActive method is static, you are not able to invoke non-static methods such as the Base graph.

Using the SelectMulti method, you may need to define the actual database fields you want returned as arguments or it may always return null.

Here’s a good example that may help. This uses Database slots and a foreach loop around the PXDatabase.SelectMulti method to retrieve values from the database. This should give you an idea of how to accomplish what you need.

https://www.acumatica.com/blog/using-modular-graph-extensions-to-avoid-mega-graphs/

Userlevel 4
Badge

@mbridges00 thank you for the time. The issue is that I need to locate the Setup DAC Extension to retrieve my control fields from it, not from the standard setup DAC. Selecting fields from standard DAC will not help even if it returns a value.

Userlevel 4
Badge

I am not sure if this is the best practice in Acumatica Platform but the below code solved my issue for now.

public static bool IsActive()
{
using (PXDataRecord setup = PXDatabase.SelectSingle<PreferencesGeneral>(new PXDataField<HCLSMPreferencesGeneral.usrHCLAPInvoiceApprovalWorkflow>()))
{
return setup != null && setup.GetString(0) == HCLEPWorkflows.EnhancedWorkflow;
}
}

 

Badge

I thought most screens referencing a setup table declare the setup as a view.

For instance: 

public class HCLAPInvoiceEntry : PXGraphExtension<APInvoiceEntry>
{
pubic PXSetup<PreferencesGeneral> setup;

public static bool IsActive()
{
HCLSMPreferencesGeneral setupExt = setup.GetExtension<HCLSMPreferencesGeneral>();

return (setupExt != null) ? setupExt.UsrHCLAPInvoiceApprovalWorkflow == HCLEPWorkflows.EnhancedWorkflow : false;
}
}

 

Edit:

Ah, but it’s static. Ok, I get it.

Userlevel 4
Badge

@darylbowman thanks for the comment. Yes, I do have the setup in my public views but I do not think you can get the extension from the view using GetExtension method, or at least I do not know how.

Userlevel 4
Badge

@darylbowman  Sorry, I saw your edit later.

Reply


About Acumatica ERP system
Acumatica Cloud ERP provides the best business management solution for transforming your company to thrive in the new digital economy. Built on a future-proof platform with open architecture for rapid integrations, scalability, and ease of use, Acumatica delivers unparalleled value to small and midmarket organizations. Connected Business. Delivered.
© 2008 — 2022  Acumatica, Inc. All rights reserved