Hi all! I’m trying to make a BPM to create a new Header Misc Charge in the Quote.
Here it is ‘my’ code:
string msg = '';
using (var svc = Ice.Assemblies.ServiceRenderer.GetService<Erp.Contracts.QuoteSvcContract>(this.Db))
{
Erp.Tablesets.UpdExtQuoteTableset ds = new Erp.Tablesets.UpdExtQuoteTableset(); // tableset for update data
bool errorOccurred;
Erp.Tablesets.QuoteHedRow qhrow = new Erp.Tablesets.QuoteHedRow // minimum required for QuoteHed
{
Company = Session.CompanyID,
QuoteNum = quotenum
};
ds.QuoteHed.Add(qhrow);
msg = "Adding Misc Charge " + quotenum;
this.PublishInfoMessage(msg, Ice.Common.BusinessObjectMessageType.Information, Ice.Bpm.InfoMessageDisplayMode.Individual, "", "");
Erp.Tablesets.QuoteHedMscRow mscrow = new Erp.Tablesets.QuoteHedMscRow // new values for header Misc Charge
{
Company = Session.CompanyID,
QuoteNum = quotenum,
//QuoteLine = 1,
//QtyNum = 1,
SeqNum = 0,
MiscCode = "Extra verniciatura",
Description = "Extra verniciatura",
MiscAmt = 500,
DocMiscAmt = 500,
FreqCode = "E"
};
//mscrow.SetUDField<System.Boolean>("50",(bool)true);
ds.QuoteHedMsc.Add(mscrow);
try
{
BOUpdErrorTableset boUpdateErrors = svc.UpdateExt(ref ds, true, true, out errorOccurred); // hold any returned errors
if (errorOccurred)
{
if (boUpdateErrors != null && boUpdateErrors.BOUpdError.Count > 0)
{
msg = msg + System.Environment.NewLine + boUpdateErrors.BOUpdError[0].ErrorText + " (" + boUpdateErrors.BOUpdError[0].TableName + ")";
}
}
else
{
Erp.Tablesets.QuoteTableset dsSO = svc.GetByID(quotenum);
if (dsSO != null)
{
this.dsHolder.Attach(dsSO);
if (dsSO.QuoteMsc.Count > 0)
{
msg = msg + System.Environment.NewLine + dsSO.QuoteMsc[0].MiscAmt.ToString();
}
}
msg = string.Empty; // remove error record if all completed successfully
}
this.PublishInfoMessage(msg, Ice.Common.BusinessObjectMessageType.Information, Ice.Bpm.InfoMessageDisplayMode.Individual, "", "");
}
catch (Exception e)
{
msg = msg + System.Environment.NewLine + "Update Exception " + e.Message;
this.PublishInfoMessage(msg, Ice.Common.BusinessObjectMessageType.Information, Ice.Bpm.InfoMessageDisplayMode.Individual, "", "");
}
}
I tried to follow the steps in the other discussions but
this doesn’t work, every time it throws me a
“Adding Misc Charge xxxxxxx
There are no records in the table ds.QuoteHed (QuoteHedMsc)”
error.
I can’t understand why, can someone help me please?
Hi! Thanks for the answer!
I modified the code (Only for the fields of the Misc Charge)
but it keeps sayin ‘There are no records in the table ds.QuoteHed’
string msg = string.Empty;
var ttQuoteHed_Row = (from row in ttQuoteHed select row).FirstOrDefault();
//where row.Added() || row.Updated()
if (ttQuoteHed_Row != null)
{
var quoteNum = ttQuoteHed_Row.QuoteNum;
msg += quoteNum.ToString();
using (var quoteSvc = Ice.Assemblies.ServiceRenderer.GetService<Erp.Contracts.QuoteSvcContract>(this.Db))
{
// This code adds / updates a header Misc Freight Charge
Erp.Tables.QuoteMsc OrderMsc;
int quoteLine = 0;
int qtyNum = 0;
string sMiscCode = "EX";
string sMiscDesc = "Extra vernicitura";
string sMiscFreq = "E";
decimal dTotAmt = 500;
var soTs = new QuoteTableset();
// Check if the Freight Record exists already
var QuoteMsc_Row = (from row in Db.QuoteMsc where row.QuoteNum == quoteNum && row.MiscCode == sMiscCode && (string.Compare(row.Company, Session.CompanyID, true) == 0 ) select row).FirstOrDefault();
if ((QuoteMsc_Row == null))
{
quoteSvc.GetNewQuoteHedMsc(ref soTs, quoteNum, quoteLine, qtyNum);
var orderMscNew = soTs.QuoteHedMsc.FirstOrDefault();
orderMscNew.MiscCode = sMiscCode;
orderMscNew.Description = sMiscDesc;
orderMscNew.FreqCode = sMiscFreq;
quoteSvc.GetMiscChrgDefaults(ref soTs, "QuoteHedMsc");
orderMscNew = soTs.QuoteHedMsc.FirstOrDefault();
orderMscNew.MiscAmt = dTotAmt;
orderMscNew.DocMiscAmt = dTotAmt;
msg += "Added New";
}
quoteSvc.Update(ref soTs);
this.dsHolder.Attach(soTs);
}
}
this.PublishInfoMessage(msg,Ice.Common.BusinessObjectMessageType.Information, Ice.Bpm.InfoMessageDisplayMode.Individual,"","");
I did a customization (code) that calculates the price for the Misc Charge and put in a custom field QuoteHed.ExtraVern_c.
Then with the BPM Erp.Quote.Update (on the condition that when the value of ExtraVern_c is changed it starts) I need to create a Misc Charge.
Hi @surendrapal, thank you for sharing the misc charge code. I have implemented and have it working to a degree. A couple of things that I have tried to do but without success is to modify the MiscAmt if the charge already exists or to delete the charge altogether if certain criteria on the quote are met. Could you possibly give me some help / advice?
Best regards
Adrian
Hi, I am trying to do the same thing as yourself but to add a charge and struggling, would you mind sharing what you have done such as I am presuming it is a post processing but are you having a condition then placing the code or invoking different methods then custom code?
I have managed to create the same on sales order entry but as this invokes masterupdate it was a lot easier to call the methods then use custom code.
To delete the carriage charge I had it based on a ud field being true,
invoke get by id,
custom code dsSalesOrder.OHOrderMsc.Where(row => row.MiscCode == "crr").FirstOrDefault().RowMod = "D";
invoke sales update
custom code dsSalesOrder.OHOrderMsc.Remove(dsSalesOrder.OHOrderMsc.Where(row => row.MiscCode == "crr").FirstOrDefault());
invoke sales update again
Hi Kirsty,
I have it working as I want it now. Thanks to @surendrapal
In my case, I want to apply a freight charge to quotes over a certain value but certain lines on the quote may be exempt from the charge. I used a customization on the quote to give me the value and if it was over the amount set I placed it in Freight_c, if not I placed zero in Freight_c. I then had a pre proc method directive with a condition Freight_c changes from any to another, invoking a post process directive with just the custom code below.
Hope this helps you
Adrian.
var ttQuoteHed_Row = ttQuoteHed.FirstOrDefault();
if (ttQuoteHed_Row == null)
return;
var quoteNum = ttQuoteHed_Row.QuoteNum;
decimal freightCharge = Convert.ToDecimal(ttQuoteHed_Row["Freight_c"]);
using (var quoteSvc = Ice.Assemblies.ServiceRenderer.GetService<Erp.Contracts.QuoteSvcContract>(this.Db))
{
// This code adds / updates a header Misc Freight Charge
Erp.Tables.QuoteMsc OrderMsc;
int quoteLine = 0;
int qtyNum = 0;
string sMiscCode = "CAHO";
string sMiscDesc = "Carriage-Home";
string sMiscFreq = "E";
decimal dTotAmt = freightCharge;
var soTs = new Erp.Tablesets.QuoteTableset();
// Check if the Freight Record exists already
var QuoteMsc_Row = Db.QuoteMsc.With(LockHint.UpdLock).Where(row => row.QuoteNum == quoteNum && row.MiscCode == sMiscCode && (string.Compare(row.Company, Session.CompanyID, true)) == 0).FirstOrDefault();
if ((QuoteMsc_Row == null))
{
quoteSvc.GetNewQuoteHedMsc(ref soTs, quoteNum, quoteLine, qtyNum);
var orderMscNew = soTs.QuoteHedMsc.FirstOrDefault();
orderMscNew.MiscCode = sMiscCode;
orderMscNew.Description = sMiscDesc;
orderMscNew.FreqCode = sMiscFreq;
quoteSvc.GetMiscChrgDefaults(ref soTs, "QuoteHedMsc");
orderMscNew = soTs.QuoteHedMsc.FirstOrDefault();
orderMscNew.MiscAmt = dTotAmt;
orderMscNew.DocMiscAmt = dTotAmt;
quoteSvc.Update(ref soTs);
}
else
{
if(dTotAmt > Decimal.Zero)
{
QuoteMsc_Row.MiscAmt = dTotAmt;
QuoteMsc_Row.DocMiscAmt = dTotAmt;
soTs = quoteSvc.GetByID(quoteNum);
}
else
{
Db.QuoteMsc.Delete(QuoteMsc_Row);
Db.Validate();
}
}
this.dsHolder.Attach(soTs);
}
Hey I am also trying to do this with intermittent success. I have it adding the charge when I want it to. But it seems to delete the charge when I complete the tasks associated with processing the quote. Any idea what would make the charge disappear?
Let me clarify. All I have to do is hit Refresh on the quote and it loses the Misc. Charge that was just added. I must be missing something silly. Why isn’t it sticking? I am adding to QuoteHedMsc for what its worth.