Solved

Cannot insert data using database scripts feature

  • 11 April 2023
  • 4 replies
  • 125 views

Badge

I am using the customization project function. To insert my data into the database with the tables as updateFile and UploadFile when I Publish. So I wrote a script to be able to insert the data into the database script section.


. But I got a message from Acu's support team that I can't do it this way.

 

So is there any other way for me to help fulfill the above requirement?

icon

Best answer by Evgeny Afanasiev 11 April 2023, 14:40

View original

4 replies

Userlevel 3
Badge

Hi Phat,

Yes, as per requirement custom SQL scripts are forbidden, beside some specific cases, although definition for both MSSQL and MySQL would be needed.

Please use Files section in the Customization Project Editor in order to add the file to the customization project. For this I would suggest to place the file in the desired location on your development instance first, so when you would add the file to the customization project, the path will be saved as well. This way it will be deployed in the same path on production instance.
 

If it is an image and your requirement is to use it just for UI for your custom screen, then it should be possible to use it straight away without serializing it to DB. If you need it in Database as a File, you can use the UploadFileMaintenance graph instance in the implementation of your Customization Plug-in.

Userlevel 6
Badge +4

Hi @phat 

 

I suggest you implement that insertion after your package is published through Plugins. There is an event after publishing on the context of each tenant where you can take care of data setups and adjustments.

 

public class SXPlugIn : CustomizationPlugin
{
//This method executed after customization was published and website was restarted.
public override void UpdateDatabase()
{
MyGraphMaint graph = PXGraph.CreateInstance<MyGraphMaint>();
if(graph.MySetupLogic(...))
{
this.WriteLog(string.Format("Data adjusted in {0}.", PXInstanceHelper.CurrentCompany));
}
}
}

Inside “MySetupLogic” you code normal Acumatica framework logic with Caches interactions etc.

This why you become database agnostic and avoid any error you might have running your SQL script.

 

Hope this help

Userlevel 6
Badge +3

Hi @phat 

 

I suggest you implement that insertion after your package is published through Plugins. There is an event after publishing on the context of each tenant where you can take care of data setups and adjustments.

​​​@Leonardo Justiniano 

I need to do something similar to this.  Does this Plugin need to be in a separate package, or can I put this code in my main VS application?

 

Userlevel 6
Badge +3

@Leonardo Justiniano Nevermind that...I just put it in my project.  WORKED AWESOME!!!

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