Skip to main content
Solved

Setup Form Auto Save on Publish

  • January 21, 2022
  • 5 replies
  • 137 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();
     }
}

Best answer by Naveen Boga

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"),
                );
}
		}
}		

 

View original
Did this topic help you find an answer to your question?

5 replies

Dmitrii Naumov
Acumatica Moderator
Forum|alt.badge.img+7
  • Acumatica Moderator
  • 632 replies
  • January 21, 2022

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.


jinin
Pro I
Forum|alt.badge.img+11
  • Pro I
  • 699 replies
  • January 21, 2022

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

        }

    }


Naveen Boga
Captain II
Forum|alt.badge.img+19
  • Captain II
  • 3404 replies
  • Answer
  • January 21, 2022

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"),
                );
}
		}
}		

 


  • Author
  • Freshman II
  • 9 replies
  • January 21, 2022

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


jinin
Pro I
Forum|alt.badge.img+11
  • Pro I
  • 699 replies
  • January 22, 2022

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


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings