Answered by:
Quote plugin

Question
-
I have created a quote pugin in CRM 2011 that fires when a quote changes state from Draft to Active. The plugin fires correctly, but fails to retrive the quote attributes. The following code fails to retrieve the quote data:
ServerConnection serverConnect = new ServerConnection();
ServerConnection.Configuration config = serverConnect.GetServerConfiguration();
OrganizationServiceProxy serviceProxy = ServerConnection.GetOrganizationProxy(config);
//serviceProxy.Timeout = new TimeSpan(0, 5, 0);
IOrganizationService service = (IOrganizationService)serviceProxy;
//ColumnSet cols = new ColumnSet("name");
// Retrieve data for the specified quote
Entity quote = new Entity("quote");
quote = service.Retrieve(quote.LogicalName, crmQuoteID, new ColumnSet(true));I get a generic sql error and from CRM Server event viewer I get the following error:
Query execution time of 99.7 seconds exceeded the threshold of 10 seconds. Thread: 13; Database: IDXOnline_CRM; Query: select
"quote0".StateCode as "statecode"
, "quote0".QuoteId as "quoteid"
, "quote0".OwningBusinessUnit as "owningbusinessunit"
, "quote0".OwningUser as "owninguser"
, "quote0".OwnerId as "ownerid"
, "quote0".OwnerIdType as "owneridtype"
from
Quote as "quote0"
where
("quote0".QuoteId = 'a27c15cc-c14c-e111-b5dc-00155d002338').Any help is greatly apprecited.
Thanks
Monday, February 6, 2012 1:11 PM
Answers
-
Hi,
The sql server profiler is not catching any errors. The workaround I used was to use a PostImage and cast it to an entity. Limiting the number of columns didnt solve the problem.
Thanks for your help.
Mthulisi
- Marked as answer by Mthu Wednesday, February 8, 2012 6:50 AM
Wednesday, February 8, 2012 6:50 AM
All replies
-
Sounds like an interesting problem, you are getting a timeout, but maybe do a server trace to see if you get better information.
http://crmdiagtool2011.codeplex.com/
Recreate the problem after turning it on, and then turn it off right away, as it is very verbose. See if it provides better data for you.
Jamie Miley
Check out my about.me profile!
http://mileyja.blogspot.com
Linked-In Profile
Follow Me on Twitter!Monday, February 6, 2012 3:14 PMModerator -
Also, run sql profiler at the same time maybe to catch any blocking or locking issues on the sql side too.
Jamie Miley
Check out my about.me profile!
http://mileyja.blogspot.com
Linked-In Profile
Follow Me on Twitter!Monday, February 6, 2012 3:14 PMModerator -
Since you are using a plug-in, you can rid of some of the Connection Items you have, they are not necessary. The Plug-In Context already has what you need to instantiate the OrganizationServiceProxy (see below:)
public void Execute(IServiceProvider provider) { IPluginExecutionContext context = (IPluginExecutionContext)provider.GetService(typeof(IPluginExecutionContext)); IOrganizationService _service = null; _service = ((IOrganizationServiceFactory)provider.GetService(typeof(IOrganizationServiceFactory))).CreateOrganizationService(new Guid?(context.UserId)); }
While it may not be the cause of the issue, I think it's a little better way of getting your service proxy setup. The Quote Entity in CRM has a lot of fields on it, it may be worth doing the following:1. Instead of retrieving the Quote in your code, have you looked at adding a PreImage to your plug-in? This will allow you to pull in the fields & values from the Order before the State Code change. From there you can cast your PreImage as an Entity and reference all of the properties. This will save you a call to server.
2. If you'd rather retrieve the Quote instead of a PreImage, can you limit the fields that you are returning from the Quote? Instead of doing new ColumnSet(true), do new ColumnSet(new string[] {"quoteid","quotenumber",etc....)}
I would definitely look at these suggested changes as an option but I would also recommend doing what Jamie is suggesting as well. The Query shouldn't take 99 seconds to run, definitely sounds like there could be some SQL issues causing slow performance on that table.
Jeremy
Jeremy Winchell Avtex http://blog.avtex.com
Tuesday, February 7, 2012 12:14 AM -
Jeremy makes good points to add to efficiency. I second the assertions Jeremy presents as best practice (and as such, I have marked the post as helpful), but as Jeremy also says, you should take my suggestions because I don't think it explains why a query pulling back one entity instance by it's guid should ever take that long unless something is blocking something or not going as planned. Please try the tweaks Jeremy has proposed, but also try the tracing methods on the server, as well as the SQL server to try to determine what is going wrong.
Keep us posted on the results!
Jamie Miley
Check out my about.me profile!
http://mileyja.blogspot.com
Linked-In Profile
Follow Me on Twitter!- Edited by Jamie MileyModerator Tuesday, February 7, 2012 2:36 AM
Tuesday, February 7, 2012 2:31 AMModerator -
Hi,
The sql server profiler is not catching any errors. The workaround I used was to use a PostImage and cast it to an entity. Limiting the number of columns didnt solve the problem.
Thanks for your help.
Mthulisi
- Marked as answer by Mthu Wednesday, February 8, 2012 6:50 AM
Wednesday, February 8, 2012 6:50 AM