Quote.DuplicateQuote Post-Processing BPM Help


(Joe) #1

I am trying to create a BPM that fires when duplicating a quote and then copies the source quote’s OrderQty to the new quote, but I am new to using custom code in BPMs.

If anyone cares to share some code snippets that would give me an idea of how this can be accomplished, it would be greatly appreciated. I am sure I can work through it, eventually, but I could use a little help getting there quicker.

(Joe) #2

So…here’s what I have been able to come up with; currently I’m just returning the source quote line and Qty in a MessageBox:

using (var txScope = IceContext.CreateDefaultTransactionScope())
for (int i = 0; i < callContextBpmData.Number02; i++)
foreach (var QuoteDtl_Recs in (from QuoteDtl_Row in Db.QuoteDtl
where QuoteDtl_Row.Company == Session.CompanyID && QuoteDtl_Row.QuoteNum == sourceQuote && QuoteDtl_Row.QuoteLine == i + 1
select QuoteDtl_Row))
string msg = string.Format(“Quote Line = {0}\rQuote Qty = {1}”,i + 1, QuoteDtl_Recs.OrderQty);
this.PublishInfoMessage(msg,Ice.Common.BusinessObjectMessageType.Information, Ice.Bpm.InfoMessageDisplayMode.Individual,“Quote”,“Duplicate”);
// = QuoteDtl_Recs.OrderQty;

My question is now, how do I update the new Quote’s Qty with the values from the source quote?

(Marlon Morawetz) #3

Hey :slight_smile:

Maybe you could use something like this:
var dbqt = Db.QuoteDtl.Where(p => p.Company == yourvar.Company && p.QuoteNum == yourvar.QuoteNum).FirstOrDefault();

if(dbqt != null){
dbqt.OrderQty = yourQty;

I hope I understood your question :smile:


(Joe) #4

I think I need to use a foreach loop instead of FirstOrDefault()…maybe I didn’t explain what I’m trying to do properly or maybe I’m not familiar enough with LINQ…

When Customer Service clicks “Actions -> Duplicate”, a new quote is created, but all of the line quantities on the new quote are zero. I am trying to create a BPM that will copy the quantity values from the sourceQuote to the new quote.

So far, I have been able to capture the sourceQuote number (sourceQuote param) and the sourceLine (BPM Data field callContextBpmData.Number02). Where I am having an issue is setting the new quantity in the new quote.

(Marlon Morawetz) #5

Ok maybe now i understood it…
I am using Erp.Quote.DuplicateQuote/Post-Processing:
First i am setting the BPM Data Field Character01 with the “BpmFunc.Replace(sourceLines, “~” ,”" )" expression. After that the custom Code executes:

foreach (var tt in ttQuoteDtl){

for(int i = 0; i < callContextBpmData.Character01.Length; i++ ){
	int t  = callContextBpmData.Character01[i]-'0';
	var dbqt = Db.QuoteDtl.Where(p => p.Company == tt.Company && p.QuoteNum == tt.QuoteNum && p.QuoteLine == i+1).FirstOrDefault();
	dbqt.OrderQty = Db.QuoteDtl.Where(m => m.Company == tt.Company && m.QuoteNum == sourceQuote && m.QuoteLine == t).Select(p => p.OrderQty).FirstOrDefault();




I tested it a bit and it seems to work quite good

(Joe) #6

Thank you for your help! I’d been working on this problem for too long.