In the process of building an option to mass delete Miscellaneous charges from credit requests. I can’t seem to get the DeleteMaster to fire correctly. Below is my current progress.
After doing a trace I can see that Getrows and DeleteMaster methods are used.
Using BL tester, I can load an invoice, and I can enter the ArInvoice dataset in particular InvcMisc, then delete the lines manually (hitting delete on each row), using the persist dataset option I can run the DeleteMaster passing in the invoice group, and invoice number. Everything appears to function. Checking the db I see the related InvcMisc lines removed as well as in the UI.
Doing this in a function. The deletemaster fires, but does nothing, am I updating the dataset incorrectly even though that BL tester you just delete the rows on the InvcMisc then run the delete and it works. I am retireving the dataset with GetRows and using RemoveAll() to take the InvcMisc rows out that have been selected. Debugging shows the rows being removed in the dataset. What Epicmagic is happening with BL tester that I am not replicating in the function?
Here is the code in the function that is being called from an updatable BAQ. Thoughts appreciated.
I am hesitant to just do a delete with extreme prejudice (Db.InvMisc.Delete(blah blah); in case it messes up the tax totals or any other related data. ![]()
StringBuilder sError = new StringBuilder("");
// Get list of invoices/credits that are not correction invoices
var RMAInvoiceNumbers = (from rmaline in Db.RMADtl
join invcDtl in Db.InvcDtl on new { rmaline.Company, rmaline.RMANum, rmaline.RMALine } equals new { invcDtl.Company, invcDtl.RMANum, invcDtl.RMALine }
join invcHead in Db.InvcHead on new { invcDtl.Company, invcDtl.InvoiceNum } equals new { invcHead.Company, invcHead.InvoiceNum }
into ig
from igr in ig.DefaultIfEmpty()
where rmaline.Company == Session.CompanyID
&& rmaline.RMANum == RMANum
&& igr.CorrectionInv == false
select new { invcDtl.InvoiceNum }).Distinct();
if (RMAInvoiceNumbers == null)
{
output = "Nothing to process, did you check any RMA lines for Credit?";
return;
}
foreach (var row in RMAInvoiceNumbers)
{
#if DEBUG
this.PublishInfoMessage($"InvoiceNum {row.InvoiceNum}", Ice.Common.BusinessObjectMessageType.Information, Ice.Bpm.InfoMessageDisplayMode.Individual, "", "");
#endif
this.CallService<Erp.Contracts.ARInvoiceSvcContract>(hARInvoice =>
{
// Get all records related to the misc charges for restocking fees for the passed in RMANum
// Parameters from Epicor Trace Parser
System.String whereClauseInvcHead = $"InvoiceNum = '{row.InvoiceNum}' BY InvoiceNum";
System.String whereClauseInvcDtl = $"InvcDtl.RMANum = {this.RMANum}";
System.String whereClauseInvcMisc = $"POL_RestockFee_c = true";
bool morePages;
System.Decimal grpTotalInvoiceAmt;
var ards = hARInvoice.GetRows(
whereClauseInvcHead, "", "", "",
whereClauseInvcDtl, "", "", "", "",
whereClauseInvcMisc, "", "", "", "", "", "", "","", 0, 0, out morePages
);
#if DEBUG
this.PublishInfoMessage($"RowCount {ards.InvcMisc.Count}", Ice.Common.BusinessObjectMessageType.Information, Ice.Bpm.InfoMessageDisplayMode.Individual, "", "");
#endif
if (ards != null && ards.InvcMisc.Count > 0)
{
ards.InvcMisc.RemoveAll(x => x.UDField<bool>("POL_RestockFee_c") == true);
#if DEBUG
this.PublishInfoMessage($"RowCount after remove {ards.InvcMisc.Count}", Ice.Common.BusinessObjectMessageType.Information, Ice.Bpm.InfoMessageDisplayMode.Individual, "", "");
#endif
//RMACRREQ is always the invoice group for the credit request.
hARInvoice.DeleteMaster(ref ards, "RMACRREQ", row.InvoiceNum.ToString(), out grpTotalInvoiceAmt);
#if DEBUG
this.PublishInfoMessage($"grpTotalInvoiceAmt {grpTotalInvoiceAmt} row.InvoiceNum {row.InvoiceNum}", Ice.Common.BusinessObjectMessageType.Information, Ice.Bpm.InfoMessageDisplayMode.Individual, "", "");
#endif
}
});
}
if (sError.Length == 0)
{
output = $"All related Restocking Fees deleted from all lines of RMA: {this.RMANum}.";
}
else
{
output = sError.ToString();
}