Previously we had configured a mapping rule for the sequencenumber column between the opportunityproduct and the quoteproduct. It used to work fine. Today one of our sales people asked me about why their quotes were always ordered incorrectly. I.E. the order of products specified on the opportunity wasn't copied over to the quote.
I verified the mapping rule is still in place, and fired up sql profiler to see what was going on... IT turns out:
This code is used to return the collection of opportunity products (Notice there is no order by)
exec sp_executesql N'select
"opportunityproduct0".OpportunityProductId as "opportunityproductid"
,"opportunityproduct0".ProductId as "productid"
, "opportunityproduct0".ProductTypeCode as "producttypecode"
, "opportunityproduct0".ParentBundleId as "parentbundleid"
, "opportunityproduct0".SequenceNumber as "sequencenumber"
from
OpportunityProductBase as "opportunityproduct0"
where
(("opportunityproduct0".OpportunityId = @OpportunityId0))',N'@OpportunityId0 uniqueidentifier',@OpportunityId0='A251E11F-3732-E611-9443-00155D649258'The code then appears to iterate over the collection and assigns the loop counter as the sequence number column value. This can lead to very inaccurate orders between the opportunity and the quotes, the orders are not even the same between different quotes for the same opportunity.
I investigated the subsequent update for the quotedetailbase and it doesn't update the sequence number column.
Is there a reliable way to get the sequence number from the opportunity product to the quote product? the existing relationship mapping is being ignored and without an order by the opportunity products are not guaranteed to be returned in any given order. I have full profile traces which I can provide if needed.
Thanks, Bill







