Add a Misc Charge to Quote Head via BPM

,

Hi every one,
I am trying to add a misc charge to the QuoteHed using a BPM. The diagnostic messages are showing except the “Adding Misc Charges” one and I am not getting any errors, but also no misc charge either. Am I going about it in the right way or have I just missed something?
Thanks in advance
Adrian

string msg = "";
var ttQuoteDtl_xRow = (from ttQuoteDtl_Row in ttQuoteDtl
											where (ttQuoteDtl_Row.RowMod == "A"
											|| ttQuoteDtl_Row.RowMod == "U")											
											select ttQuoteDtl_Row).FirstOrDefault();
if (ttQuoteDtl_xRow != null)
{
		msg = "Line Exists";
		this.PublishInfoMessage(msg, Ice.Common.BusinessObjectMessageType.Information, Ice.Bpm.InfoMessageDisplayMode.Individual, "", "");
		var QuoteHed_xRow = (from QuoteHed_Row in Db.QuoteHed
												where QuoteHed_Row.Company == ttQuoteDtl_xRow.Company
												&& QuoteHed_Row.QuoteNum == ttQuoteDtl_xRow.QuoteNum
												select QuoteHed_Row).FirstOrDefault();
		if (QuoteHed_xRow != null)
		{

				msg = "Quote Header Exists";
				this.PublishInfoMessage(msg, Ice.Common.BusinessObjectMessageType.Information, Ice.Bpm.InfoMessageDisplayMode.Individual, "", "");
				var QuoteMsc_xRow = (from QuoteMsc_Row in Db.QuoteMsc
												where QuoteMsc_Row.Company == QuoteHed_xRow.Company
												&& QuoteMsc_Row.QuoteNum == QuoteHed_xRow.QuoteNum
												select QuoteMsc_Row).FirstOrDefault();
				
				if (QuoteMsc_xRow != null)
				{
				msg = "Adding Misc Charge";
				this.PublishInfoMessage(msg, Ice.Common.BusinessObjectMessageType.Information, Ice.Bpm.InfoMessageDisplayMode.Individual, "", "");
				
				using (var txScope = IceContext.CreateDefaultTransactionScope())
				{
				QuoteMsc newRow = new QuoteMsc();
				Db.QuoteMsc.Insert(newRow);
				newRow.Company = Session.CompanyID;
				newRow.MiscCode = "NPC";
				newRow.Description = "Non Standard Paint Charge";
				newRow.Type = "Amount";
				newRow.DocMiscAmt = 50;
				newRow.FreqCode = "L";
				Db.Validate();
				txScope.Complete();
				}
			}
		}
}

You are checking to see if the QuoteMsc exists… (it won’t) I think your If statement needs to be
if (QuoteMsc_xRow == null)

Thanks @josecgomez, I tried that and got this error’ I should have mentioned that it is a pre processing method directive on the Quote update

This is how we do it:

using (var svc = Ice.Assemblies.ServiceRenderer.GetService<Erp.Contracts.QuoteSvcContract>())
            {
                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);
                
                Erp.Tablesets.QuoteHedMscRow mscrow = new Erp.Tablesets.QuoteHedMscRow // new values for header Misc Charge
                {
                    Company = Session.CompanyID,
                    QuoteNum = quotenum,
                    QuoteLine = line,
                    QtyNum = qnum,
                    SeqNum = seq,
                    MiscCode = shipvia,
                    Description = sv.Description,
                    MiscAmt = ccharge,
                    DocMiscAmt = dcharge,
                    FreqCode = sv.FreqCode
                };
                mscrow.SetUDField<System.Boolean>("ManualCharge_c",(bool)sv.Variable_c);
                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 + 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
                    }
                }
                catch (Exception e)
                {
                    msg = msg + System.Environment.NewLine + "Update Exception " + e.Message;
                }
            }

This is dumped from a bigger bit of code, but you can probably get the gist. It’s in a post-processing method directive enabled from a pre-processing check one.

2 Likes

I have to say @dhewi, that looks a lot better than mine. I will have a go at implementing it. Thank you very much for sharing it.

I’ve been struggling with the Epicor Quote BO off and on for quite some time now, so I’m uncomfortably aware of the problems and it’s nice (hopefully) to be able to smooth the way for someone else.

1 Like

Hi Adrain

Long time no speak,

With what you are doing rather than adding the row at the Db level I would suggest doing this through call the business object within your bpm code as it will mean that the quote totals and tax etc will be calculated correctly.

I am currently away on holiday and will be back home on the 12th Aug, if you are no further along reach out to me and I will send you some code snippets,

Kind Regards,

Neil Jones

1 Like

Hi @Neil_Jones , how’s things? Yes it has been a while. Still got your business card on my desk though and often refer to the excellent report you did for us.
Enjoy your holiday and I shall definitely be in touch when you get back!

Hi @dhewi ,
I am trying out your code and it works with no errors, but I do not get a Misc charge showing on the quote. However when I do A QUICK baq it is there;


I can see that the Line is showing as 0. Could this be the reason?

string msg = "";
int quotenum = Convert.ToInt32(callContextBpmData.Number01);
using (var svc = Ice.Assemblies.ServiceRenderer.GetService<Erp.Contracts.QuoteSvcContract>())
            {
                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 = 10,
                    MiscCode = "NPC",
                    Description = "Non Standard Paint Charge",
                    MiscAmt = 50,
                    DocMiscAmt = 50,
                    FreqCode = "L"
                };
                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 + 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
                    }
                }
                catch (Exception e)
                {
                    msg = msg + System.Environment.NewLine + "Update Exception " + e.Message;
                }
            }

Quote Misc charges are odd beasts. They all show up in the same QuoteMsc table, but you deal with them through the BO via either QuoteHedMsc or QuoteDtlMsc. If you use the first, then the QuoteLine will be ignored and it will arrive in the table as QuoteLine = 0, because that’s how the BO knows it’s a header charge. If you use the second then you need a non-zero QuoteLine that matches a QuoteDtl (and an associated bare-bones row in the UpdateExt DataSet) to avoid an error.

Your original post said that you were trying to add a misc charge to the QuoteHed …?

Sorry for the confusion. I am trying to add the charge to QuoteHed, I was just clutching at straws a bit as to why the charge wasn’t appearing

In which case I’m a bit baffled too. I would have put QuoteLine = 0 in the code but that hasn’t actually affected anything. You’ve got a good many Misc Charges in the table, by the looks! I can’t see any obvious reason why they wouldn’t show up in the Quote itself.

Can you see any differences between those records and any that have been added manually?

I have it working now, I commented out the Line and Qty values and it works.
I shall need to look at restricting the amount of times this charge can be entered on one quote to once, as I noticed while testing I could add it many times.
Thanks Daryl

1 Like

why do not you condition the run by after certain relevant changes ?

1 Like

Apologies if I’m straying into the “too basic”, but one of the nice things about working with UpdateExt is that you can deal with updates to existing rows using the same mechanism as adding new ones - if you’re specific enough about the row details it’ll update what’s already there, and if nothing matches then it will create a new row. So if you tweak the code you have in just the right way, the problem should go away on its own - though obviously it’s most efficient if you can take no action when none is needed.

Anyway, I’m sure you can sort that part out.

2 Likes

You could never be “too basic” for me @dhewi :laughing:

1 Like

validating against record existed is a good idea, the only difference though is it means that your custom code will run every time the update or/and ExtUpdate happen up to the validation line, whereas adding the condition prior to the code will skip the whole thing.

Yes, where it makes sense to skip the whole procedure naturally that’s the best thing to do.

In practice, I’ve found it’s often best to compromise and build the checks into the code, so you preserve the possibility of different actions based on what you’re testing for. Generally those checks aren’t any more taxing than widget conditions and you can then skip the expensive things like BO calls as needed. Meanwhile, if someone decides there are situations where an update is called for as well as a new row, then most of the code is already in place to handle it, which is one of the benefits of UpdateExt.

1 Like

Hi,

Just in case anyone else struggles in getting misc on a Quote LINE item you need to use GetNewQuoteMsc and also the field to update is DocDspMiscAmt (Make sure it is after GetMiscChrgDefaults!) For Order Line Item it is just standard MiscAmt
Hope this saves someone a few hours that I have spent getting to this point!
Code AttachedBPM Add Misc Charge Working- USE THIS ONE!.cs (3.2 KB)

Kind regards

Mark

3 Likes