Solved

Setup Form Auto Save on Publish

  • 21 January 2022
  • 5 replies
  • 122 views

Hi,

I am working on a customization and I am looking to automatically save the default values in a setup form when the customization is installed. We would like to have the record inserted into the database without users needing to go to the setup form.

I am using a constructor in the setup graph to insert a record but I am getting an error: “The cache PageSetup has not been found in the list of auto-initialized caches.”

Is there a better approach for this? I have included my code below. Thank you!

 

public SelectFrom<PageSetup>.View Setup;

public PageSetupMaint() // Constructor
{

     // Check if a record exists in the database
     PXResultset<PageSetup> recs = PXSelect<PageSetup,
     Where<PageSetup.dnloadStockItem, Equal<Required<PageSetup.dnloadStockItem>>>>.Select(this);

     if (recs.Count < 1)
     {
          Setup.Insert(new PageSetup());
          Save.Press();
     }
}

icon

Best answer by Naveen Boga 21 January 2022, 19:56

View original

5 replies

Userlevel 7
Badge +11

Hi @noahmiller02 

I hope the below sample code helps you. I tried with the Inventory preference screen(INSetup)

Example:

          try
            {
                INSetupMaint graph = PXGraph.CreateInstance<INSetupMaint>();

                if (graph.setup.Current == null)
                {

                    INSetup newSetup = new INSetup()
                    {
                        // Assign DAC field values
                        HoldEntry = true,
                        ReplanBackOrders = true,
                    };

                    graph.setup.Insert(newSetup);
                    graph.Actions.PressSave();                  
                }
            }
            catch (Exception ex)
            {
                WriteLog(ex.Message);
            }

Thank you all! Yes, the Customization Plug In is exactly what I was look for. I appreciate the feedback and examples. Here is my updated code. I am still working out the select statement to read from the provider.

 

public override void UpdateDatabase()
{
     try
     {
          Graph prefs = PXGraph.CreateInstance<Graph>();

          PXDataRecord record = prefs.ProviderSelectSingle(prefs.GetType());

          if (record == null)
          {
               DAC newRec = new DAC();

               prefs.ProviderInsert<DAC>(
                    new PXDataFieldAssign<Graph.a>(newRec.a.Value)
               );
          }
     }
     catch (Exception ex)
     {
          WriteLog(ex.Message);
     }
}

Userlevel 7
Badge +17

Hi @noahmiller02  Here is the sample example for your reference.

 public class ThrottleConstants : CustomizationPlugin
{
public override void UpdateDatabase()
{
ProjectList graph = PXGraph.CreateInstance<ProjectList>();

DACName records = PXSelectReadonly<DACName>.Select(graph);
if (records == null)
{
PXDatabase.Insert<DACName>(
new PXDataFieldAssign<DACName.customField1>("Test API"),
new PXDataFieldAssign<DACName.customField2>("30000"),
);

PXDatabase.Insert<DACName>(
new PXDataFieldAssign<DACName.customField1>("Test API2"),
new PXDataFieldAssign<DACName.customField2>("30000"),
);
}
}
}

 

Userlevel 7
Badge +11

Hi @noahmiller02 

You can achieve this through CustomizationPlugin extention. This will execute when we publish the package.

 

  public class CustomizationPluginExtn : CustomizationPlugin
    {
        public override void UpdateDatabase()
        {
                      // Initialize graph object and write your logic

        }

    }

Userlevel 7
Badge +5

I think what you are looking for is Customization Plug In

https://help-2021r2.acumatica.com/(W(133))/Help?ScreenId=ShowWiki&pageid=c69443fe-4d32-47a9-85aa-b2882aa259ef

 

It allows you to execute some custom code as a part of customization publishing process.

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