Error when using QuoteClose – Microsoft Dynamics CRM Forum Community Forum

Forum Post: Change the Filter On option on Opportunity Associated View for Account form

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<QuoteResponse>();
			foreach (var attr in entityCollection.Entities.ToArray()) {
				var quoteId = attr.Attributes["quoteid"].ToString();
				quoteList.Add(new Quote().Get(quoteId));

			foreach (var quote in quoteList) {

					0 - Draft
					1 - Active
					2 - Won
					3 - Closed

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

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

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

					// 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;


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

					Console.WriteLine($"Deleting Draft Quote: {}");
					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. 

[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=, 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=, 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?

Source link

Leave a reply

Please enter your comment!
Please enter your name here