Skip to main content
Solved

Unable to Insert records despite permission

  • 17 September 2024
  • 4 replies
  • 41 views

Forum|alt.badge.img

Hi Everyone,

I am working on building a process screen that will allow us to update our customer-salesperson assignments easily. This information is stored in the CustSalesPeople table/DAC and has not been customized (according to the DAC schema). For some reason, I am able to delete the records that I need to, but I am unable to insert any new rows. I have tried both the Insert() and Update() methods, but neither seems to be working.

I have verified that both AllowDelete and AllowInsert are true. The variable “graph” below is an instance of CustomerMaint.

My deleting logic looks like this:

//Delete all the entries of CustSalesPeople for that customer

 PXResultset<CustSalesPeople> existingRecords = PXSelect<CustSalesPeople,
     Where<CustSalesPeople.bAccountID, Equal<Required<CustSalesPeople.bAccountID>>>>
     .Select(graph, accountToUpdate.BAccountID);

      foreach (CustSalesPeople record in existingRecords)

      {

      graph.Caches<CustSalesPeople>().Delete(record);

      }

  graph.Actions.PressSave();

 

//Insert the new salesperson data

CustSalesPeople newRecord = new CustSalesPeople();
        newRecord.BAccountID = accountToUpdate.BAccountID;
        newRecord.LocationID = location.LocationID;
        newRecord.SalesPersonID = salespersonID;
        newRecord.CommisionPct = commissionPct;
        newRecord.IsDefault = sourceItem.IsDefaultSalesperson;

graph.Caches<CustSalesPeople>().Insert(newRecord); // I have also tried Update(newRecord)

graph.Actions.PressSave();

 

All of the fields that I am inserting are not null, and since CustomerMaint is successfully deleting a record, I cannot understand why it cannot (or seems not to) insert a new row of data.

Am I missing something obvious? Getting pretty close to pulling my hair out on this one…

Thanks,

Aaron

Best answer by aiwan

HI @aaronjkeeney 

 

A way I have done it previous is below:

 var gilMaint = PXGraph.CreateInstance<GuildMaint>();
 var order = Base.CurrentDocument.Current;
 var header = gilMaint.ISORecords.Insert(); //Here you could put YourDac yourDac = new YourDac()
 header.DocType = "NCR";
 header.SOOrderNbr = order.OrderNbr;
 header.CustomerID = order.CustomerID;
 gilMaint.ISORecords.Update(header);

I think the key difference in our methods is that I reference the View of the Graph, whereas you target Cache.

 

also, silly question but is your deleting code in the same file/.dll?

If so, it could be deleting the records as it creates them.

 

Aleks

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

4 replies

Forum|alt.badge.img+7
  • Captain II
  • 274 replies
  • Answer
  • September 20, 2024

HI @aaronjkeeney 

 

A way I have done it previous is below:

 var gilMaint = PXGraph.CreateInstance<GuildMaint>();
 var order = Base.CurrentDocument.Current;
 var header = gilMaint.ISORecords.Insert(); //Here you could put YourDac yourDac = new YourDac()
 header.DocType = "NCR";
 header.SOOrderNbr = order.OrderNbr;
 header.CustomerID = order.CustomerID;
 gilMaint.ISORecords.Update(header);

I think the key difference in our methods is that I reference the View of the Graph, whereas you target Cache.

 

also, silly question but is your deleting code in the same file/.dll?

If so, it could be deleting the records as it creates them.

 

Aleks


Forum|alt.badge.img
  • Author
  • Freshman I
  • 10 replies
  • September 23, 2024

Hi Aiwan,

You were pretty close! I did end up needing to update the view, but there was also an issue with a 3-part composite key.

As for the deleting, I do have some code to manage that -- essentially just keeping a list of records that have been added via this instance of the screen. Still testing, but seems to be working thus far.

Any idea as to why the delete would work but not the insert when I was referencing the cache? It’s just curiosity at this point, but it strikes me as odd that deleting records would be easier and more accessible than inserting them…

Thanks,

Aaron


Forum|alt.badge.img+7
  • Captain II
  • 274 replies
  • September 23, 2024

HI @aaronjkeeney 

 

To be completely honest with you I do not know but what I do know is that the cache is a temporary data hold and after saving it should go into the database.

This may be due to my inexperience, but I haven’t seen anyone, yet, invoke the cache straight from the graph.

I have seen graph.View.Cache.Current;  so this could be where the issue stems from.

 

Maybe @darylbowman could offer some clarity?

 

Aleks


darylbowman
Captain II
Forum|alt.badge.img+13
  • 1455 replies
  • September 23, 2024

I have seen this done successfully in various places, but I must admit I don’t really understand it either. I always use the views because it’s much cleaner code, visually, if not functionally.


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