Bpm Converting Quote to SO not mapping correctly

When converting quote to SO with multiple line items the rep groups are not mapping correctly from the quote on subsequent lines. Line 1/release 1 maps as expected but subsequent lines only mapped the ship to rep group (QuoteHed.Character10).

Erp.Tables.OrderHed OrderHed ;
Erp.Tables.OrderDtl OrderDtl ;
Erp.Tables.OrderRel OrderRel ;
Erp.Tables.QuoteHed QuoteHed ;

OrderHed = (from OH_row in Db.OrderHed
where OH_row.Company == Session.CompanyID && OH_row.OrderNum == orderNum
select OH_row).FirstOrDefault();
if (OrderHed != null)
{
OrderDtl = (from OD_row in Db.OrderDtl
where OD_row.Company == OrderHed.Company && OD_row.OrderNum == OrderHed.OrderNum
select OD_row).FirstOrDefault();
if (OrderDtl != null)
{
OrderRel = (from OR_row in Db.OrderRel
where OR_row.Company == Session.CompanyID && OR_row.OrderNum == orderNum
select OR_row).FirstOrDefault();
if (OrderRel != null)
{
QuoteHed = (from qh_row in Db.QuoteHed
where qh_row.Company == OrderHed.Company && qh_row.QuoteNum == OrderDtl.QuoteNum
select qh_row).FirstOrDefault();
if (QuoteHed != null)
{
OrderRel.Character02 = QuoteHed.Character12;
OrderRel.Character10= QuoteHed.Character13;
OrderRel.Character01 = QuoteHed.Character10;

    }
  }
}
  Db.Validate(OrderHed);

}

Hello @Tripb44

Make a test code block and try this code, I don’t think you need the first reference to the OrderHed table unless you need to set something on that too??

var OrderDtls = (from OD_row in Db.OrderDtl where OD_row.Company == Session.Company && OD_row.OrderNum == orderNum select OD_row).ToList();
if (OrderDtls != null)
{
foreach(var OrderDtl in OrderDtls)
{
var OrderRel = (from OR_row in Db.OrderRel where OR_row.Company == Session.CompanyID && OR_row.OrderNum == orderNum select OR_row).FirstOrDefault();
if (OrderRel != null)
{
var QuoteHed = (from qh_row in Db.QuoteHed where qh_row.Company == Session.Company && qh_row.QuoteNum == OrderDtl.QuoteNum select qh_row).FirstOrDefault();
if (QuoteHed != null)
{
OrderRel.Character02 = QuoteHed.Character12;
OrderRel.Character10= QuoteHed.Character13;
OrderRel.Character01 = QuoteHed.Character10;

    }
  }
}
Db.Validate(); //I don't think you need this line
} 

I’m getting some errors

I am thinking the issue is coming somewhere from the bpm might only be looking and applying the changes to the first row/line one and any subsequent lines/rows are not being ran through the method?

Ok, I see the error,

Remove this part of the code

image

And where I referred to Session.Company it should have been Session.CompanyID

Updated code below

var OrderDtls = (from OD_row in Db.OrderDtl where OD_row.Company == Session.CompanyID && OD_row.OrderNum == orderNum select OD_row).ToList();
if (OrderDtl != null)
{
foreach(OrderDtl in OrderDtls)
{
var OrderRel = (from OR_row in Db.OrderRel where OR_row.Company == Session.CompanyID && OR_row.OrderNum == orderNum select OR_row).FirstOrDefault();
if (OrderRel != null)
{
var QuoteHed = (from qh_row in Db.QuoteHed where qh_row.Company == Session.CompanyID && qh_row.QuoteNum == OrderDtl.QuoteNum select qh_row).FirstOrDefault();
if (QuoteHed != null)
{
OrderRel.Character02 = QuoteHed.Character12;
OrderRel.Character10= QuoteHed.Character13;
OrderRel.Character01 = QuoteHed.Character10;

    }
  }
}
Db.Validate(); //I don't think you need this line
}