Solved

Hide a screen from workspaces if a feature is disabled

  • 26 July 2023
  • 8 replies
  • 156 views

Userlevel 3
Badge

Hi,

Is it possible to hide a screen from the workspaces where it is displayed if a given feature is not enabled ?

To describe my situation, I have a graph A and its extension B.

    public class A: PXGraph<A>
    {
        public SelectFrom<EAPInvoice>.Where<True.IsEqual<False>>.View emptyView;
    }

    public class B: PXGraphExtension<B>
    {
        #region Properties
        public static bool IsActive() => PXAccess.FeatureInstalled<FeaturesSetExt.myFeature>();

         ...

    }

A screen has been created using graph A and has been added to the “Payable” workspace. It uses fields from a DAC that also depend on the feature.

    public class MyDAC: IBqlTable
    {
        public static bool IsActive() => PXAccess.FeatureInstalled<FeaturesSetExt.myFeature>();

}

When “myFeature” is disabled from CS100000, none of fields from the DAC are displayed ; that’s OK. However, the screen is always available in the “Payable” workspace whereas I’d like it not being seen.

icon

Best answer by aaghaei 26 July 2023, 15:42

View original

8 replies

Userlevel 7
Badge +9

Please see this I posted while ago. It will give the idea of Features.xml and how interacts with screens.

 

Userlevel 3
Badge

Hello @aaghaei , thanks for your reply. I my case, the execution of the instruction PXAccess.FeatureInstalled<FeaturesSetExt.myFeature>() works fine. My problem is that the screen caption remains visible in the workspaces where it is assigned, even when the feature is not enabled. I thought it would be hidden. I guess I have forgotten something...

Userlevel 7
Badge +9

@ygagnaire12 no worries. That is understood. If you go to the end of the tread, where I am putting screenIDs into Features xml, it is what you need.

Userlevel 3
Badge

Hello @aaghaei , sorry, I have missed this step, I should need holidays. I try it immediatly. Thank you very much !

Userlevel 3
Badge

@aaghaei , your solution works fine. Once again, thank you very much !

Userlevel 7
Badge +9

@ygagnaire12 happy to hear it worked. The post I referred you to, is very long and messy. That would be great if you could summarize what you did along with the related code snippets to share here at the end of your post for other people reference in case someone else comes across the same issue that I believe will be the case. Of course No pressure just if you have time and like to share a neat a concise summary.

Userlevel 3
Badge

Hello @aaghaei,

Sorry for the delay. Here are the steps we have followed to add a new feature in our customization project. Hope it is clear enought to be helpful for others.

 

Step 1 : Add of the new feature as a new field of the “FeatureSet” DAC

 

In the FeaturesSet.xml file of the customization project, declaration the new column:

<Table TableName="FeaturesSet">

    <Column TableName="FeaturesSet" ColumnName="OurNewFeature" ColumnType="bool" AllowNull="True" DecimalPrecision="0" DecimalLength="0" IsNewColumn="True" IsUnicode="True" />

...

</Table>

Then, add of the new field in the DAC. To do that, we have used a DAC extension that we have called “FeatureSetExt”. 

 

public abstract class cegEInvoicing : PX.Data.BQL.BqlBool.Field<cegEInvoicing> { }

[Feature(false, typeof(FeaturesSet.integrationModule), DisplayName = "Electronic invoicing")]

[PXDefault(false, PersistingCheck = PXPersistingCheck.Nothing)]

public bool? OurNewFeature {get;set;}

 

Step 2 : Add of the new feature to the CS100000 screen

 

In the CS100000.aspx.cs file of the customization file, add of the new feature in the configuration description. In our case, we have created a dedicated mechanism that loads it dynamically in the screen. This step is probably not necessary but it is a convenient way for us to hide completely a feature easily.

public partial class Page_CS100000 : PXPage

{

    protected void Page_Init(object sender, EventArgs e)

    {

        var featureVisibility = ParseConfig(@"

FinancialModule

    FinancialStandard

        Branch

        MultiCompany

        AccountLocations

#       Reporting1099

        InvoiceRounding

        OurNewFeature"

);

        PXCache cache = this.ds.DataGraph.Caches[typeof(FeaturesSet)];

 

        foreach (string field in cache.Fields)

        {

            // skip unwanted features

            if(!featureVisibility.Contains(field))

            {

                continue;

            }         

            // The rest of this method creates a PXCheckBox for current field (which represents

            // in this case a feature), and adds it dynamically to the screen :

            PXCheckBox control = new PXCheckBox();

 

            //…

            this.form.TemplateContainer.Controls.Add(control);

   }

 

    // converts feature visibility configuration into a dictionary

    private IList<string> ParseConfig(string config)

    {

        // this method converts a string to a list of feature names

    }

 

}

 

Step 3 : configures what types of objects are impacted by the feature

 

In the Features.xml file, add of  a new element “Feature” having a “Name” attribute with our new feature’s name.

 

<?xml version="1.0" encoding="utf-8"?>

<Features Type="Abcd.CS.DAC.FeaturesSetExt" Key="0">

 

  <Feature Name="OurNewFeature">

              <Access ScreenID="AP50XX11" />

              <Access ScreenID="AP30XX12" />

  </Feature>

 

 

</Features>

 

The two lines in red above were missing in my code and that’s why the concerned screens were still vivible even when the feature was disabled.

Userlevel 7
Badge

Thank you for sharing your solution with the community @ygagnaire12!

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 — 2024  Acumatica, Inc. All rights reserved