Question

Issue updating a field in custom table

  • 25 October 2023
  • 0 replies
  • 60 views

Userlevel 2

Good day,

 

I am having an issue updating a record in my custom table, I have a trigger in the INItemStats table, when the Maxcost changes the trigger adds a record to the custom table, these records are used in my processing screen only if their status is 0, after processing and doing the expected action I want to change the status of the record to 1, but Every attempt I do it gives me the same error, “Another process has updated EVTCMaxcost your changes will be lost”. And in the code is PX.Data.LockViolationException.

 

I have changed the code multiple times to update, to save in the database and cleared the cache, but always get the same error. (I can’t use this. right now, because of the modification  made and the method being static. )

Cache.Persist(PXDBOperation.Update);

 

this.ProcessView.Cache.Update(item);

 

this.ProcessView.Cache.PersistUpdated(item);

 

this.ProcessView.Cache.Persist(PXDBOperation.Update);

 

this.ProcessView.Cache.Clear();

 

this.Actions.PressSave();

 

this.Persist();

public class EVTCUpdateCostProcess : PXGraph<EVTCUpdateCostProcess>
{

public PXProcessing<EVTCMaxCost, Where<EVTCMaxCost.status, Equal<Zero>>> ProcessView;
public PXCancel<EVTCMaxCost> Cancel;

[InjectDependency]
public static RequestService _srvc { get; } = new APILogin();

public EVTCUpdateCostProcess()
{
var cache = this.Caches[typeof(EVTCMaxCost)];
ProcessView.SetProcessCaption("Process");
ProcessView.SetProcessAllCaption("Process All");


ProcessView.SetProcessDelegate(delegate (List<EVTCMaxCost> costrecord)
{
ExecuteProcess(costrecord, cache);
});

}


public static void ExecuteProcess(List<EVTCMaxCost> costrecord, PXCache Cache)
{
foreach (var item in costrecord)
{

string respxml = _srvc.GetItemIncludeCostQueryRequest(item.InventoryCD);

XmlSerializer _serializer = new XmlSerializer(typeof(WebcreteXML));
TextReader reader = new StringReader(respxml);
WebcreteXML rec = (WebcreteXML)_serializer.Deserialize(reader);
reader.Close();

if (rec.WebcreteXMLMsgsRs.ItemQueryRs.ItemRet != null)
{


var itemRet = rec.WebcreteXMLMsgsRs.ItemQueryRs.ItemRet;
string code = itemRet.Code;
string StandardCost = item.MaxCost.ToString();

_srvc.GetItemUpdateRequest(code, StandardCost);


if (item != null)
{
// Check if the status is already 1 (processed)
if (item.Status != 1)
{

// Update the status
item.Status = 1;

Cache.Update(item);
}


}
else
{
continue;
}
}
}
Cache.Persist(PXDBOperation.Update);

}


}

 


0 replies

Be the first to reply!

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