web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Unanswered

Error when using QuoteClose

(0) ShareShare
ReportReport
Posted on by 5

Hi team,

I'm currently experiencing an issue when I try and use QuoteCloseRequest in my code:

		public void CloseQuotes(string opportunityGuid) {
			var dataVerseConnection = new ServiceClient(_connectionString);
			if (!dataVerseConnection.IsReady) {
				throw new Exception("Authentication Failed!");
			}

			var columns = new ColumnSet(new string[] { "quoteid" });

			var entityCollection = DynamicsConnection.GetEntityCollection(dataVerseConnection, "quote", "opportunityid", opportunityGuid, columns);

			var quoteList = new List();
			foreach (var attr in entityCollection.Entities.ToArray()) {
				var quoteId = attr.Attributes["quoteid"].ToString();
				quoteList.Add(new Quote().Get(quoteId));
			}

			foreach (var quote in quoteList) {

				/*
					StateCode
					0 - Draft
					1 - Active
					2 - Won
					3 - Closed

					StatusCode
					1 - In Progress (Draft)
					2 - In Progress (Active)
					4 - Won
					5 - Lost
					7 - Revised
				*/

				if (quote.stateCodeName == "Active") {

					Console.WriteLine($"Closing Active Quote: {quote.name}");

					// close quote
					quote.stateCode = 3;
					quote.stateCodeName = "Closed";
					quote.statusCode = 7;
					quote.statusCodeName = "Revised";


					var req = new CloseQuoteRequest();
					var quoteClose = new Entity("quoteclose");
					quoteClose.Attributes.Add("quoteid", new EntityReference("quote", new Guid(quote.guid)));
					req.QuoteClose = quoteClose;
					req.RequestName = "CloseQuote";
					var o = new OptionSetValue();
					o.Value = -1;
					req.Status = o;

					dataVerseConnection.Execute(req);
					

				} else if (quote.stateCodeName == "Draft") {

					Console.WriteLine($"Deleting Draft Quote: {quote.name}");
					new Quote().Delete(quote);
				}

			}
		}

This is the error received when I run this code:

System.Private.CoreLib: Exception while executing function: OpportunityCloseQuotes. 

Microsoft.PowerPlatform.Dataverse.Client: Failed to connect to Dataverse. System.Private.CoreLib: One or more errors occurred. (Exception - Fault While initializing client - RefreshInstanceDetails). 
Microsoft.PowerPlatform.Dataverse.Client: Exception - Fault While initializing client - RefreshInstanceDetails. 
Microsoft.PowerPlatform.Dataverse.Client: Exception - Failed to lookup current organization data. 
Microsoft.PowerPlatform.Dataverse.Client: 

[A]Microsoft.Crm.Sdk.Messages.RetrieveCurrentOrganizationResponse cannot be cast to [B]Microsoft.Crm.Sdk.Messages.RetrieveCurrentOrganizationResponse. 

Type A originates from 'Microsoft.Crm.Sdk.Proxy, Version=9.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' in the context 'Default' at location '*\DynamicsFunctions\bin\Release\netcoreapp3.1\bin\Microsoft.Crm.Sdk.Proxy.dll'. 

Type B originates from 'Microsoft.Cds.Sdk.Proxy, Version=9.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' in the context 'Default' at location '*\DynamicsFunctions\bin\Release\netcoreapp3.1\bin\Microsoft.Cds.Sdk.Proxy.dll'.

When I comment out the CloseQuoteRequest instantiation, the code runs fine.

What is happening, and what changes can I make to make this code run?

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the August Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Syed Aqib Raza Profile Picture

Syed Aqib Raza 97

#2
Daniyal Khaleel Profile Picture

Daniyal Khaleel 89 Most Valuable Professional

#3
11manish Profile Picture

11manish 71 Super User 2026 Season 2

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans