Insert Customer Location from an action - acumatica

I have an action where a new customer location is created.
So far, I'm just trying to load the page with an existing record.
With this code, the result is positive
public virtual IEnumerable NewLocation(PXAdapter adapter)
{
CustomerLocationMaint locationGraph = PXGraph.CreateInstance<CustomerLocationMaint>();
Location locationRow = new Location();
locationGraph.Location.Current = locationGraph.Location.Search<Location.locationID>(116, "ABARTENDE");
locationGraph.Location.Insert(locationRow);
throw new PXRedirectRequiredException(locationGraph, null) { Mode = PXBaseRedirectException.WindowMode.NewWindow };
return adapter.Get();
}
However, this other version loads the page blank:
public virtual IEnumerable NewLocation(PXAdapter adapter)
{
CustomerLocationMaint locationGraph = PXGraph.CreateInstance<CustomerLocationMaint>();
Location locationRow = new Location();
locationRow.BAccountID = 109; //ABARTENDE
locationRow.LocationID = 116; //MAIN
locationGraph.Location.Insert(locationRow);
throw new PXRedirectRequiredException(locationGraph, null) { Mode = PXBaseRedirectException.WindowMode.NewWindow };
return adapter.Get();
}
I need to have a version similar to the second one, because eventually, the new LocationCD will be entered from this action.
Any ideas?

In the second example, you're trying to set the LocationID explicitly, this is an identity field that needs to be assigned. I found a couple of examples in the source:
public PXDBAction<BAccount> addLocation;
[PXUIField(DisplayName = Messages.AddNewLocation)]
[PXButton(ImageKey = PX.Web.UI.Sprite.Main.DataEntry)]
public virtual void AddLocation()
{
var row = BAccount.Current;
if (row == null || row.BAccountID == null) return;
LocationMaint graph = null;
switch (row.Type)
{
case BAccountType.VendorType:
graph = PXGraph.CreateInstance<AP.VendorLocationMaint>();
break;
case BAccountType.CustomerType:
graph = PXGraph.CreateInstance<AR.CustomerLocationMaint>();
break;
default:
graph = PXGraph.CreateInstance<LocationMaint>();
break;
}
var newLocation = (Location)graph.Location.Cache.CreateInstance();
newLocation.BAccountID = row.BAccountID;
var locType = LocTypeList.CustomerLoc;
switch (row.Type)
{
case BAccountType.VendorType:
locType = LocTypeList.VendorLoc;
break;
case BAccountType.CombinedType:
locType = LocTypeList.CombinedLoc;
break;
}
newLocation.LocType = locType;
graph.Location.Insert(newLocation);
PXRedirectHelper.TryRedirect(graph, PXRedirectHelper.WindowMode.NewWindow);
}

Related

Unable to open SO screen SO301000 using Action from Quote screen CR304500

I have created a Action called CREATE SO in Sales Quote screen to create Sales order.
I am unable to open the sales order screen using this action. though the sales order is getting created
but the SO screen is not opening while creating the SO. I am not sure where i am making mistake in my code. Please suggest. Thanks.
#region Create Sales Order
public PXAction<CRQuote> createSalesOrder;
[PXUIField(DisplayName = "Create SO", MapEnableRights = PXCacheRights.Update, MapViewRights = PXCacheRights.Update)]
[PXProcessButton(CommitChanges = true)]
public IEnumerable CreateSalesOrder(PXAdapter adapter)
{
QuoteMaint graphObject = PXGraph.CreateInstance<QuoteMaint>();
foreach (CRQuote quote in adapter.Get())
{
//Create resultset for Quote Details
PXResultset<CROpportunityProducts> PXSetLine = PXSelect<CROpportunityProducts,
Where<CROpportunityProducts.quoteID,
Equal<Required<CROpportunityProducts.quoteID>>>>.Select(this.Base, quote.QuoteID);
List<CROpportunityProducts> QuoteList = new List<CROpportunityProducts>();
foreach (CROpportunityProducts line in PXSetLine)
{
QuoteList.Add(line);
}
PXLongOperation.StartOperation(this, () => CreateSalesOrderMethod(quote, QuoteList));
yield return quote;
}
}
//Private Method for Create Sales Order
public virtual void CreateSalesOrderMethod(CRQuote quote, List<CROpportunityProducts> QuoteList)
{
//Base.Save.Press();
bool var_orderCreated = false;
bool erroroccured = false;
string ErrMsg = "";
SOOrderEntry orderGraphObjet = PXGraph.CreateInstance<SOOrderEntry>();
SOOrder orderHeaderObject = new SOOrder();
QuoteMaint currGRPH = PXGraph.CreateInstance<QuoteMaint>();
BAccount customer = PXSelect<BAccount, Where<BAccount.bAccountID, Equal<Current<CRQuote.bAccountID>>>>.Select(this.Base, quote.BAccountID);
if (customer.Type == "CU")
{
orderHeaderObject.CustomerID = quote.BAccountID;
}
else
{
throw new PXException("Business Account not converted to Customer yet"); // THIS ERROR IS ALSO NOT SHOWING WHILE ENCOUNTERING.
}
orderHeaderObject.CuryOrderTotal = quote.CuryProductsAmount;
orderHeaderObject.CuryTaxTotal = quote.CuryTaxTotal;
orderHeaderObject.OrderDesc = quote.Subject;
orderHeaderObject = orderGraphObjet.CurrentDocument.Insert(orderHeaderObject);
orderGraphObjet.CurrentDocument.Current = orderHeaderObject;
orderGraphObjet.Actions.PressSave();
orderHeaderObject = orderGraphObjet.CurrentDocument.Current;
foreach (CROpportunityProducts tran in QuoteList)
{
SOLine transline = new SOLine(); //EMPTY DAC OBJECT
transline.OrderNbr = orderHeaderObject.OrderNbr;
transline.BranchID = orderHeaderObject.BranchID;
transline.InventoryID = tran.InventoryID;
transline.TranDesc = tran.Descr;
transline.UOM = tran.UOM;
transline.OrderQty = tran.Quantity;
transline.SiteID = tran.SiteID;
transline.CuryUnitPrice = tran.CuryUnitPrice;
transline.CuryExtPrice = tran.CuryExtPrice;
orderGraphObjet.Transactions.Insert(transline); //INSERT DAC INTO DATAVIEW
CROpportunityProductsExt xOppProductExt = PXCache<CROpportunityProducts>.GetExtension<CROpportunityProductsExt>(tran);
SOLineExt _soLext = PXCache<SOLine>.GetExtension<SOLineExt>(transline); // GET DAC ENTENSION
_soLext.UsrXSeqID = xOppProductExt.UsrXSequenceID;
_soLext.UsrXGroupID = xOppProductExt.UsrXGroupID;
_soLext.UsrInternalRemk = xOppProductExt.UsrInternalRemk; // ASSIGN CUSTOM FIELDS
orderGraphObjet.Transactions.Update(transline); // UPDATE DAC OBJECT IN DATAVIEW
}
orderGraphObjet.Actions.PressSave();
var_orderCreated = true;
//if (orderGraphObjet != null && orderHeaderObject != null)
if (var_orderCreated)
{
orderGraphObjet.Document.Current = orderHeaderObject; // HERE I AM GETTING THE OrderType as well as OrderNbr to open the Document.
throw new PXRedirectRequiredException(orderGraphObjet, "Document") { Mode = PXBaseRedirectException.WindowMode.NewWindow };
}
}
#endregion
}
}
The issue is that the redirection is in the PXLongOperation. A PXLongOperation starts a separate thread that is not related with the UI. In order to solve this you can use the PXCustomInfo structure to talk back with the UI thread after the long operation finishes and thus be able to redirect to the so screen.
// PXCustomInfoDefinition
public sealed class SORedirectionCustomInfo: IPXCustomInfo
{
private PXGraph _OrderGraph;
public SORedirectionCustomInfo(PXGraph orderGraph)
{
_OrderGraph = orderGraph;
}
public void Complete(PXLongRunStatus status, PXGraph graph)
{
if (status == PXLongRunStatus.Completed && graph is <YourQuoteGraphType>)
{
throw new PXRedirectRequiredException(orderGraphObjet, "Document") { Mode = PXBaseRedirectException.WindowMode.NewWindow };
}
}
}
// Long Operation Method
public virtual void CreateSalesOrderMethod(CRQuote quote, List<CROpportunityProducts> QuoteList)
{
// Your code to create SO....
if (var_orderCreated)
{
PXLongOperation.SetCustomInfo(new SORedirectionCustomInfo(orderGraphObjet));
}
}
This should be able to redirect successfully once the long operation is completed and the order is created.

Shipment Confirmation and Update IN through code is not working

I have a requirement to create shipment document, shipment confirmation and update In on a Sales order Transfer document.
The following code is used for shipment confirmation
public string CreateShipment()
{
bool flag = false;
string _retval = string.Empty;
using (IEnumerator<PXResult<SOOrderShipment>> enumerator = Base.shipmentlist.Select(Array.Empty<object>()).GetEnumerator())
{
if (enumerator.MoveNext())
{
SOOrderShipment current = enumerator.Current;
flag = true;
}
}
if (flag)
{
string Mess = "Error: Shipment already created.";
throw new PXException(Mess);
}
SOShipmentEntry sOShipmentEntry = PXGraph.CreateInstance<SOShipmentEntry>();
//SOOrderEntry sOOrderEntry = PXGraph.CreateInstance<SOOrderEntry>();
//sOOrderEntry.Caches.Clear();
SOOrder sOOrder = Base.Document.Current;
int? nullable = new int?(0);
int? customerLocationID = new int?(0);
if (sOOrder != null)
{
nullable = sOOrder.CustomerID;
customerLocationID = sOOrder.CustomerLocationID;
}
int? siteID = new int?(0);
//SOShipmentEntry sOShipmentEntry1 = PXGraph.CreateInstance<SOShipmentEntry>();
SOShipment destinationDocument = sOShipmentEntry.Document.Insert();
destinationDocument.ShipmentType = "T";
destinationDocument = sOShipmentEntry.Document.Update(destinationDocument);
destinationDocument.Operation = "I";
destinationDocument = sOShipmentEntry.Document.Update(destinationDocument);
using (IEnumerator<PXResult<SOLine>> enumerator1 = PXSelectReadonly<SOLine, Where<SOLine.orderType, Equal<Required<SOLine.orderType>>, And<SOLine.orderNbr, Equal<Required<SOLine.orderNbr>>>>>.Select(Base, new object[] { Base.Document.Current.OrderType, Base.Document.Current.OrderNbr }).GetEnumerator())
{
if (enumerator1.MoveNext())
{
SOLine line = (SOLine)enumerator1.Current;
siteID = line.SiteID;
}
}
destinationDocument.SiteID = siteID;
destinationDocument.DestinationSiteID = sOOrder.DestinationSiteID;
destinationDocument = sOShipmentEntry.Document.Update(destinationDocument);
//sOOrderEntry.Document.Current = sOOrder;
if (Base.Document.Current != null)
{
DocumentList<SOShipment> documentList = new DocumentList<SOShipment>(sOShipmentEntry);
sOShipmentEntry.CreateShipment(Base.Document.Current, sOShipmentEntry.Document.Current.SiteID, sOShipmentEntry.Document.Current.ShipDate, new bool?(false), "I", documentList);
if (sOShipmentEntry.Document.Current.ShipmentNbr != null)
{
SOOrderEntry sOOrderEntry1 = PXGraph.CreateInstance<SOOrderEntry>();
sOOrderEntry1.Clear();
sOOrderEntry1.Document.Current = sOOrder;
int? openShipmentCntr = Base.Document.Current.OpenShipmentCntr;
if ((openShipmentCntr.GetValueOrDefault() > 0 ? openShipmentCntr.HasValue : false))
{
sOOrder.Status = SOOrderStatus.Shipping;
sOOrder.Hold = new bool?(false);
sOOrderEntry1.Document.Update(sOOrder);
sOOrderEntry1.Save.Press();
_retval = sOShipmentEntry.Document.Current.ShipmentNbr;
}
}
}
return _retval;
}
The following code confirms the shipment and update IN.
private void ConfirmShipment(string shipmentnbr)
{
SOShipmentEntry sOShipmentEntry = PXGraph.CreateInstance<SOShipmentEntry>();
SOOrderEntry sOOrderEntry = PXGraph.CreateInstance<SOOrderEntry>();
sOShipmentEntry.Clear();
sOOrderEntry.Clear();
sOOrderEntry.Document.Current = PXSelect<SOOrder, Where<SOOrder.orderType, Equal<Required<SOOrder.orderType>>, And<SOOrder.orderNbr, Equal<Required<SOOrder.orderNbr>>>>>.Select(sOOrderEntry, Base.Document.Current.OrderType, Base.Document.Current.OrderNbr);
sOShipmentEntry.Document.Current = PXSelect<SOShipment,Where<SOShipment.shipmentNbr, Equal<Required<SOShipment.shipmentNbr>>>>.Select(sOShipmentEntry,shipmentnbr);
if(sOShipmentEntry.Document.Current!= null && sOOrderEntry.Document.Current != null)
{
sOShipmentEntry.ConfirmShipment(sOOrderEntry, sOShipmentEntry.Document.Current);
sOShipmentEntry.UpdateIN.Press();
}
}
I am able to select sales order in purchase receipt transfer document, but the shipment document status still shows open and not completed.
I have tried the run confirm shipment on the document which is already confirmed through code from the menu of shipment document and I am getting the following error
“Shipment counters are corrupted.”

how to attach an XML file in the "Files" tab of an action

I have a big question, you can attach XML through an action, when you import the XML and also save it in the "Files" tab, the question is. if it can be attached?.
Here is an example image:
what is missing is that I automatically attach in the "Files" tab, when I put upload
Here is my code where, I attached the XML
public PXAction<ARInvoice> CargarXML;
[PXUIField(DisplayName = "Carga de código hash")]
[PXButton()]
public virtual void cargarXML()
{
var Result = NewFilePanel.AskExt(true);
if (Result == WebDialogResult.OK)
{
PX.SM.FileInfo fileInfo = PX.Common.PXContext.SessionTyped<PXSessionStatePXData>().FileInfo["CargaSessionKey"];
string result = System.Text.Encoding.UTF8.GetString(fileInfo.BinData);
ARInvoice ari = Base.Document.Current;
xtFECodHashEntry graph2 = PXGraph.CreateInstance<xtFECodHashEntry>();
var pchExt = ari.GetExtension<ARRegisterExt>();
string Valor = "";
XmlDocument xm = new XmlDocument();
xm.LoadXml(result);
XmlNodeList elemList = xm.GetElementsByTagName("ds:DigestValue");
for (int i = 0; i < elemList.Count;)
{
Valor = (elemList[i].InnerXml);
break;
}
PXLongOperation.StartOperation(Base, delegate ()
{
xtFECodHash dac = new xtFECodHash();
dac.RefNbr = ari.RefNbr;
dac.DocType = ari.DocType;
dac.Nrocomprobante = ari.InvoiceNbr;
dac.Hash = Valor;
dac.Tipo = pchExt.UsrTDocSunat;
graph2.xtFECodHashs.Insert(dac);
graph2.Actions.PressSave();
});
}
}
If you have the FileInfo object which it seems like you do I have used something like this:
protected virtual void SaveFile(FileInfo fileInfo, PXCache cache, object row)
{
if (fileInfo == null)
{
return;
}
var fileGraph = PXGraph.CreateInstance<UploadFileMaintenance>();
if (!fileGraph.SaveFile(fileInfo, FileExistsAction.CreateVersion))
{
return;
}
if (!fileInfo.UID.HasValue)
{
return;
}
PXNoteAttribute.SetFileNotes(cache, row, fileInfo.UID.Value);
}
So in your example you could call this method as shown above using the following:
SaveFile(fileInfo, Base.Document.Cache, Base.Document.Current);

Sending notification to requester when PO is created in Acumatica

I need to be able to send an email to the original requester when a PO is created from a Requisition in Acumatica 6.1.
Per Acumatica, the Notification screen cannot handle this functionality, so I have this code to extend the POOrder Entry graph, which sends an email to the Customer's contact email from the Requisition when a PO is created (along with the RQRequisitionEntryExt trigger):
public class POOrderEntryExt : PXGraphExtension<POOrderEntry>
{
private bool sendEmailNotification = false;
public bool SendEmailNotification
{
get
{
return sendEmailNotification;
}
set
{
sendEmailNotification = value;
}
}
[PXOverride]
public void Persist(Action del)
{
using (var ts = new PXTransactionScope())
{
if (del != null)
{
del();
}
if (SendEmailNotification)
{
bool sent = false;
string sError = "Failed to send E-mail.";
try
{
Notification rowNotification = PXSelect<Notification,
Where<Notification.name, Equal<Required<Notification.name>>>>
.Select(Base, "PurchaseOrderNotification");
if (rowNotification == null)
throw new PXException("Notification Template was not found.");
var order = Base.Document.Current;
var requisition = (RQRequisition)PXSelect<RQRequisition,
Where<RQRequisition.reqNbr, Equal<Current<POOrder.rQReqNbr>>>>
.SelectSingleBound(Base, new object[] { order });
if (requisition.CustomerID != null)
{
var customer = (BAccountR)PXSelectorAttribute.Select<RQRequisition.customerID>(
Base.Caches[typeof(RQRequisition)], requisition);
if (customer != null)
{
var defCustContact = (Contact)PXSelectorAttribute.Select<BAccountR.defContactID>(
Base.Caches[typeof(BAccountR)], customer);
if (String.IsNullOrEmpty(defCustContact.EMail))
throw new PXException("E-mail is not specified for Customer Contact.");
var sender = TemplateNotificationGenerator.Create(order,
rowNotification.NotificationID.Value);
sender.RefNoteID = order.NoteID;
sender.MailAccountId = rowNotification.NFrom.HasValue ?
rowNotification.NFrom.Value :
PX.Data.EP.MailAccountManager.DefaultMailAccountID;
sender.To = defCustContact.EMail;
sent |= sender.Send().Any();
}
}
}
catch (Exception Err)
{
sent = false;
sError = Err.Message;
}
if (!sent)
throw new PXException(sError);
}
ts.Complete();
}
}
}
And this to modify RQRequisitionEntry:
public class RQRequisitionEntryExt : PXGraphExtension<RQRequisitionEntry>
{
public PXAction<RQRequisition> createPOOrder;
[PXButton(ImageKey = PX.Web.UI.Sprite.Main.DataEntry)]
[PXUIField(DisplayName = Messages.CreateOrders)]
public IEnumerable CreatePOOrder(PXAdapter adapter)
{
PXGraph.InstanceCreated.AddHandler<POOrderEntry>((graph) =>
{
graph.GetExtension<POOrderEntryExt>().SendEmailNotification = true;
});
return Base.createPOOrder.Press(adapter);
}
}
In order to send an email to the Requester's (Employee) contact email from the Request, I modified the POOrderEntryExt to pull the information from the Request object and the Employee's Contact email (I left the RQRequisitionEntryExt the same and in place):
public class POOrderEntryExt : PXGraphExtension<POOrderEntry>
{
private bool sendEmailNotification = false;
public bool SendEmailNotification
{
get
{
return sendEmailNotification;
}
set
{
sendEmailNotification = value;
}
}
[PXOverride]
public void Persist(Action del)
{
using (var ts = new PXTransactionScope())
{
if (del != null)
{
del();
}
if (SendEmailNotification)
{
bool sent = false;
string sError = "Failed to send E-mail.";
try
{
Notification rowNotification = PXSelect<Notification,
Where<Notification.name, Equal<Required<Notification.name>>>>
.Select(Base, "PurchaseOrderNotification");
if (rowNotification == null)
throw new PXException("Notification Template was not found.");
var order = Base.Document.Current;
var requisition = (RQRequisition)PXSelect<RQRequisition,
Where<RQRequisition.reqNbr, Equal<Current<POOrder.rQReqNbr>>>>
.SelectSingleBound(Base, new object[] { order });
var request = (RQRequest)PXSelectJoin<RQRequest,
InnerJoin<RQRequisitionContent,
On<RQRequisitionContent.orderNbr, Equal<RQRequest.orderNbr>>>,
Where<RQRequisitionContent.reqNbr, Equal<POOrder.rQReqNbr>>>
.SelectSingleBound(Base, new object[] { order });
if (request.EmployeeID != null)
{
var employee = (BAccountR)PXSelectorAttribute.Select<RQRequest.employeeID>(
Base.Caches[typeof(RQRequest)], request);
if (employee != null)
{
var defEmpContact = (Contact)PXSelectorAttribute.Select<BAccountR.defContactID>(
Base.Caches[typeof(BAccountR)], employee);
if (String.IsNullOrEmpty(defEmpContact.EMail))
throw new PXException("E-mail is not specified for Employee Contact.");
var sender = TemplateNotificationGenerator.Create(order,
rowNotification.NotificationID.Value);
sender.RefNoteID = order.NoteID;
sender.MailAccountId = rowNotification.NFrom.HasValue ?
rowNotification.NFrom.Value :
PX.Data.EP.MailAccountManager.DefaultMailAccountID;
sender.To = defEmpContact.EMail;
sent |= sender.Send().Any();
}
else
throw new PXException("Customer not found.");
}
else
throw new PXException("Request not found.");
}
catch (Exception Err)
{
sent = false;
sError = Err.Message;
}
if (!sent)
throw new PXException(sError);
}
ts.Complete();
}
}
}
I can get the original code to send an email in my development environment, but my modified code only returns the outer "Failed to send E-mail" error.
Can anyone help point me in the right direction to get my modifications to work?
Because in Acumatica there is one-to-many relationship between RQRequisition and RQRequest, I believe the better approach is to loop through all requests linked to the current requisition and compose a list of requester's emails. After that we can go ahead and send emails to all requesters as part of the Create Orders operation:
public class POOrderEntryExt : PXGraphExtension<POOrderEntry>
{
private bool sendEmailNotification = false;
public bool SendEmailNotification
{
get
{
return sendEmailNotification;
}
set
{
sendEmailNotification = value;
}
}
[PXOverride]
public void Persist(Action del)
{
using (var ts = new PXTransactionScope())
{
if (del != null)
{
del();
}
if (SendEmailNotification)
{
bool sent = false;
string sError = "Failed to send E-mail.";
try
{
Notification rowNotification = PXSelect<Notification,
Where<Notification.name, Equal<Required<Notification.name>>>>
.Select(Base, "PONotification");
if (rowNotification == null)
throw new PXException("Notification Template was not found.");
var order = Base.Document.Current;
var emails = new List<string>();
var requests = PXSelectJoinGroupBy<RQRequest,
InnerJoin<RQRequisitionContent,
On<RQRequest.orderNbr,
Equal<RQRequisitionContent.orderNbr>>>,
Where<RQRequisitionContent.reqNbr,
Equal<Required<RQRequisition.reqNbr>>>,
Aggregate<GroupBy<RQRequest.orderNbr>>>
.Select(Base, order.RQReqNbr);
foreach (RQRequest request in requests)
{
if (request.EmployeeID != null)
{
var requestCache = Base.Caches[typeof(RQRequest)];
requestCache.Current = request;
var emplOrCust = (BAccountR)PXSelectorAttribute
.Select<RQRequest.employeeID>(requestCache, request);
if (emplOrCust != null)
{
var defEmpContact = (Contact)PXSelectorAttribute
.Select<BAccountR.defContactID>(
Base.Caches[typeof(BAccountR)], emplOrCust);
if (!String.IsNullOrEmpty(defEmpContact.EMail) &&
!emails.Contains(defEmpContact.EMail))
{
emails.Add(defEmpContact.EMail);
}
}
}
}
foreach (string email in emails)
{
var sender = TemplateNotificationGenerator.Create(order,
rowNotification.NotificationID.Value);
sender.RefNoteID = order.NoteID;
sender.MailAccountId = rowNotification.NFrom.HasValue ?
rowNotification.NFrom.Value :
PX.Data.EP.MailAccountManager.DefaultMailAccountID;
sender.To = email;
sent |= sender.Send().Any();
}
}
catch (Exception Err)
{
sent = false;
sError = Err.Message;
}
if (!sent)
throw new PXException(sError);
}
ts.Complete();
}
}
}

Changes in cache saved in database before calling Persist()

I have created a new grid with Case classes in Contract Template screen which updates case classes for particular Contract Template. There is a checkbox for every case class in the grid and when I check/Uncheck, RowUpdatedEventHandler is triggered and I am updating the contents of Cache.
I have overridden Persist() to save the contents of the cache in Database. But before Persist() is being called the changes are saved in the database and the cache is cleared.Please, Someone help me with this
protected void CRCaseClass_RowUpdated(PXCache sender, PXRowUpdatedEventArgs
e)
{
CRCaseClass newrow = (CRCaseClass)e.Row;
CRCaseClass oldrow = (CRCaseClass)e.OldRow;
ContractTemplate row = contracts.Current;
CaseContract c = new CaseContract();
CRCaseClassExt newrow_ext =
PXCache<CRCaseClass>.GetExtension<CRCaseClassExt>(newrow);
CRCaseClassExt oldrow_ext =
PXCache<CRCaseClass>.GetExtension<CRCaseClassExt>(oldrow);
c.CaseClassID = newrow.CaseClassID;
c.ContractID = row.ContractID;
c.Active = newrow_ext.Check.Value;
caseContract.Insert(c);
}
[PXOverride]
public void Persist()
{
bool c = caseContract.Cache.IsInsertedUpdatedDeleted;
CaseContract cc = null;
IEnumerable cacheRecords = caseContract.Cache.Inserted;
List<CaseContract> recordsToBePersisted = new List<CaseContract>();
ContractTemplate row = contracts.Current;
foreach (CaseContract cr in cacheRecords)
{
PXResultset<CaseContract> v = PXSelect<CaseContract, Where<CaseContract.contractID,
Equal<Required<ContractTemplate.contractID>>, And<CaseContract.caseClassID,
Equal<Required<CRCaseClass.caseClassID>>>>>.Select(Base, row.ContractID, cr.CaseClassID);
if (v.Count != 0 && v.Count == 1)
{
cc = v.GetEnumerator().Current;
cc.Active = cr.Active;
}
else if (v.Count == 0)
{
cc = new CaseContract();
cc.CaseClassID = cr.CaseClassID;
cc.ContractID = cr.ContractID;
cc.Active = cr.Active;
}
else {
//Error Logic
}
recordsToBePersisted.Add(cc);
}
//clean all cache
//insert all values from recordsToBePersisted
caseContract.Cache.Clear();
foreach (CaseContract i in recordsToBePersisted) {
caseContract.Insert(i);
}
Base.Persist();
The Acumatica way to override virtual methods in BLC extensions is slightly different from what you get used to with the .Net framework. Below is the updated version of your code, that should resolve the issue with empty caches. For more details on this topic, please refer to the Acumatica Customization Guide
[PXOverride]
public void Persist(Action del)
{
bool c = caseContract.Cache.IsInsertedUpdatedDeleted;
CaseContract cc = null;
IEnumerable cacheRecords = caseContract.Cache.Inserted;
List<CaseContract> recordsToBePersisted = new List<CaseContract>();
ContractTemplate row = contracts.Current;
foreach (CaseContract cr in cacheRecords)
{
PXResultset<CaseContract> v = PXSelect<CaseContract, Where<CaseContract.contractID,
Equal<Required<ContractTemplate.contractID>>, And<CaseContract.caseClassID,
Equal<Required<CRCaseClass.caseClassID>>>>>.Select(Base, row.ContractID, cr.CaseClassID);
if (v.Count != 0 && v.Count == 1)
{
cc = v.GetEnumerator().Current;
cc.Active = cr.Active;
}
else if (v.Count == 0)
{
cc = new CaseContract();
cc.CaseClassID = cr.CaseClassID;
cc.ContractID = cr.ContractID;
cc.Active = cr.Active;
}
else
{
//Error Logic
}
recordsToBePersisted.Add(cc);
}
//clean all cache
//insert all values from recordsToBePersisted
caseContract.Cache.Clear();
foreach (CaseContract i in recordsToBePersisted)
{
caseContract.Insert(i);
}
del();
}

Resources