Skip to main content
Answer

Activate Extension Conditionally doesn't return the expected value

  • November 16, 2022
  • 6 replies
  • 200 views

aaghaei
Captain II
Forum|alt.badge.img+10

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;
}
}

 

Best answer by aaghaei

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;
}
}

 

6 replies

Forum|alt.badge.img+1
  • Jr Varsity II
  • November 16, 2022

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/


aaghaei
Captain II
Forum|alt.badge.img+10
  • Author
  • Captain II
  • November 16, 2022

@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.


aaghaei
Captain II
Forum|alt.badge.img+10
  • Author
  • Captain II
  • Answer
  • November 17, 2022

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;
}
}

 


darylbowman
Captain II
Forum|alt.badge.img+15

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.


aaghaei
Captain II
Forum|alt.badge.img+10
  • Author
  • Captain II
  • November 17, 2022

@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.


aaghaei
Captain II
Forum|alt.badge.img+10
  • Author
  • Captain II
  • November 17, 2022

@darylbowman  Sorry, I saw your edit later.