Skip to main content
Solved

Issues adding DAC values onto another table in SQL.

  • July 14, 2023
  • 1 reply
  • 75 views

  • I have done the following steps:
    • Created the SQL list
    • Put the list in “Database Scripts” of the customization project.
    • Create the DAC for the database table and move it to the extension library that I'm working on.
  • I'm storing the values as follows:
  • DACName store = new DACName
  •             {
  •                 column1 = value1,
  •                 column2 = value2,
  •                 column3 = value3
  •             };
  •             PxGraphName.Caches[typeof(DACName)].Insert(store);
  •             PxGraphName.Persist();
  •             PxGraphName.Caches[typeof(DACName)].Clear();

 

  • The issue is that, whenever I run the program, I look into the table and the value isn’t stored.
  • I know information might be a bit vague but it’s to not overcomplicate things. I also haven't added anything the DAC of the table that stores the values, so if i need to add something let me know.

Best answer by davidnavasardyan

Hi @BernardoBermudez27 

When you want to insert a record into a table, you typically need to use the graph that is associated with the DAC of that table. The Insert() and Persist() methods are defined in the graph, not the cache. You also need to ensure that you have properly defined your DAC, including all DB-bound fields and their appropriate attributes, and that the DAC matches the structure of your database table.

Here is an example of how to insert a record:

 

PXGraph graph = new PXGraph(); // or any other graph that you have, like SOOrderEntry graph for SOOrder DAC

DACName dac = new DACName
{
    Column1 = value1,
    Column2 = value2,
    Column3 = value3
};

graph.Caches[typeof(DACName)].Insert(dac);
graph.Actions.PressSave();

You should make sure to save the changes after inserting a record with the PressSave() method. Persist() method saves all the changes that have been made to the data in the caches (Insert, Update, and Delete operations) since the last persisting of the data.

Also, please ensure that there is not any exception occurring during the operation.

Remember to do proper error handling and check for any errors in the row or cache after the insert operation. For instance, you can use the PXUIFieldAttribute.GetError<FieldType>(cache, data) method to check if any error was set for the specified field.

If the issue persists, please provide more context or relevant parts of your code and we might be able to give a more specific answer.

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

davidnavasardyan
Jr Varsity I
Forum|alt.badge.img+2

Hi @BernardoBermudez27 

When you want to insert a record into a table, you typically need to use the graph that is associated with the DAC of that table. The Insert() and Persist() methods are defined in the graph, not the cache. You also need to ensure that you have properly defined your DAC, including all DB-bound fields and their appropriate attributes, and that the DAC matches the structure of your database table.

Here is an example of how to insert a record:

 

PXGraph graph = new PXGraph(); // or any other graph that you have, like SOOrderEntry graph for SOOrder DAC

DACName dac = new DACName
{
    Column1 = value1,
    Column2 = value2,
    Column3 = value3
};

graph.Caches[typeof(DACName)].Insert(dac);
graph.Actions.PressSave();

You should make sure to save the changes after inserting a record with the PressSave() method. Persist() method saves all the changes that have been made to the data in the caches (Insert, Update, and Delete operations) since the last persisting of the data.

Also, please ensure that there is not any exception occurring during the operation.

Remember to do proper error handling and check for any errors in the row or cache after the insert operation. For instance, you can use the PXUIFieldAttribute.GetError<FieldType>(cache, data) method to check if any error was set for the specified field.

If the issue persists, please provide more context or relevant parts of your code and we might be able to give a more specific answer.


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