Hello I have created a plugin that executes upon Opportunity create. The purpose of the plug in the check if the recently create Opportunity is a duplicate of another opportunity. We will define a duplicate opportunity by having identical Proposal Numbers as a existing Opportunity.
If a duplicate is detected then we want to modify the proposal number programmatically and save it.
My current issue is that after saving the opportunity, the plugin seems to run but does not change the value of the intended field.
I have written a plugin previously that will auto increment a project number field on a Job entity, I based my new plugin code off of this previous plugin. The auto increment Job plugin works as expected, but the only difference between the two plugins is that, the new one has to query all the Opportunity entities in order to check for duplicates. This section of code might be the culprit because this is where I query for all the Opp entities, and then proceed to add the Proposal Number attribute of each entity into a list of strings. I think this area is the culprit because it takes a little bit to execute (about 11 seconds), when I step through the code.
List listOfProjectNumbers = new List(); var serviceContext = new OrganizationServiceContext(service); string fetchQuery = @" "; EntityCollection results = service.RetrieveMultiple(new FetchExpression(fetchQuery)); foreach (var c in results.Entities) { try { listOfProjectNumbers.Add(c.Attributes["cmc_proposalnumber"].ToString()); } catch (Exception ex) { Console.Write(ex.Message); } }
Do you guy have any insight in what the potential issue could be?