Coming soon: Your brand new Help Center & Community! Get a sneak-peek here

Quote FindProduct "Sequence contains no matching element" error

Hi Guys. I'm trying to look up a product in quote, using FindQuote, but i'm experiencing that i get a weird error, if i try to look up a product for an earlier version of the same alternative. I have made som demo code - Alternative 828 works fine, but 827 does not:

#setLanguageLevel 3;
NSQuoteAgent qAgent;
Integer alternative_id;
NSProduct[] prod; 
NSQuoteEntity qEnt;
NSQuoteAlternative alt;
NSQuoteVersion ver;

alternative_id = 828;
 

try{
alt = qAgent.GetQuoteAlternative(alternative_id);
ver = qAgent.GetQuoteVersion(alt.GetQuoteVersionId());
qEnt = qAgent.GetQuoteEntity(ver.GetQuoteId());
printLine('Alternative: "' + alt.GetName() + '", Version: ' + ver.GetRank().toString() + ' (ID ' + ver.GetQuoteVersionId().toString() + '), State: ' + ver.GetState().toString() + ', QuoteConnector: ' + qEnt.GetQuoteConnectionId().toString());
prod = qAgent.FindProduct(alternative_id, '700537', '');
for(Integer i = 0; i < prod.length(); i++){
  NSProduct pr = prod[i];
  printLine(pr.GetCode());
}
printLine('Products: ' + prod.length().toString());
}
catch{
  printLine(error);
}

printLine('-------------');

alternative_id = 827;
try{ 
alt = qAgent.GetQuoteAlternative(alternative_id);
ver = qAgent.GetQuoteVersion(alt.GetQuoteVersionId());
qEnt = qAgent.GetQuoteEntity(ver.GetQuoteId());
printLine('Alternative: "' + alt.GetName() + '", Version: ' + ver.GetRank().toString() + ' (ID ' + ver.GetQuoteVersionId().toString() + '), State: ' + ver.GetState().toString() + ', QuoteConnector: ' + qEnt.GetQuoteConnectionId().toString());
prod = qAgent.FindProduct(alternative_id, '700537', '');
for(Integer i = 0; i < prod.length(); i++){
  NSProduct pr = prod[i];
  printLine(pr.GetCode());
}
printLine('Products: ' + prod.length().toString());
}
catch{
  printLine(error);
}

 

Result is:

Alternative: "Products", Version: 2 (ID 768), State: 1, QuoteConnector: 2
700537-STK
Products: 1
-------------
Alternative: "Products", Version: 1 (ID 767), State: 1, QuoteConnector: 2
NetServerException: NetServer exception: Service call Quote.FindProduct failed with exception
Quote.FindProduct

Sequence contains no matching element

As you can see, the first alternative (828) finds the product 700537-STK without a sweat. But 827 is another story. Here i get the "Sequence contains no matching element" error. But that is not true, i know the product is there (which the first lookup proves). The alternatives are similar, only difference is that version 1 was sent to the customer already. I temporarily tried to change the state to draft, in order to see if that made any difference. It did not (Which is also why the state is 1 for both alternatives)

 

Any ideas what happens here? I'm also unable to add a quote line containing the product, in the old version, that function fails with the same "Sequence contains no matching element" error.

RE: Quote FindProduct "Sequence contains no matching element" error

"Sequence contains no elements" is usually returned when some internal error occured, mostly related to that something can not be found/mapped (search for "Sequence contains" on the community or bugs/wishes to find other examples).

Does quotealternative 927 maybe have a product that isn't available anymore?

 

Af: David Hollegien 3. maj 2021

RE: Quote FindProduct "Sequence contains no matching element" error

One of the products in the quote has been blocked for sales in the meantime, but i wouldn't think this should impact whether or not a product is searchable in specific alternatives? I just tried adding the blocked product to another quote without any problems, except i get the notice on the quote that a product is blocked for sales. But it saves the line without any problem.

It's blocked for sales in NAV no matter what - so i guess that should only have anything to say when placing the order?

Af: Dennis Mortensgaard 3. maj 2021

RE: Quote FindProduct "Sequence contains no matching element" error

Hei,
this is Win talking and it's been a long while since I last dug into quote but something here seemed familiar.
I take a risk and stick my neck out...

I wonder if the alternative_id parameter in FindProduct might be somewhat misleading/confusing?
We are searching for a product here, not a quoteline. So what is the alternative good for?

The alternative id merely serves as a means to retrieve the connector/connection context.

But I have seen in the QuoteManager code that behind the scenes, it is using the Quote's ActiveQuoteVersionId...
i.o.w. it is trying to find alternative_id 827 linked to the Quote's active quote version which I suspect is what fails.

/conrad.

 

 

Af: Conrad Weyns 3. maj 2021