Note that there are some explanatory texts on larger screens.

plurals
  1. POMicrosoft CRM 2011 Plugins - Simple Issue
    text
    copied!<p>I am trying to write a plugin to create a new contact entity in Microsoft CRM 2011. I'm yet to find any useful information online and I feel like I've been banging my head against a brick wall all day. The code I have posted below is giving me an error saying "The name 'service' does not exist in the current context". Can anyone tell me what's going on, please?</p> <pre class="lang-cs prettyprint-override"><code>// &lt;copyright file="PreValidateContactCreate.cs" company=""&gt; // Copyright (c) 2013 All Rights Reserved // &lt;/copyright&gt; // &lt;author&gt;&lt;/author&gt; // &lt;date&gt;8/6/2013 4:22:10 PM&lt;/date&gt; // &lt;summary&gt;Implements the PreValidateContactCreate Plugin.&lt;/summary&gt; // &lt;auto-generated&gt; // This code was generated by a tool. // Runtime Version:4.0.30319.1 // &lt;/auto-generated&gt; namespace Plugins1 { using System; using System.ServiceModel; using System.Collections.Generic; using Microsoft.Xrm.Sdk; using Microsoft.Crm.Sdk.Messages; using Microsoft.Xrm.Sdk.Client; using Microsoft.Xrm.Sdk.Discovery; using Microsoft.Xrm.Sdk.Metadata; using Microsoft.Xrm.Sdk.Query; /// &lt;summary&gt; /// PreValidateContactCreate Plugin. /// &lt;/summary&gt; public class PreValidateContactCreate: Plugin { /// &lt;summary&gt; /// Initializes a new instance of the &lt;see cref="PreValidateContactCreate"/&gt; class. /// &lt;/summary&gt; public PreValidateContactCreate() : base(typeof(PreValidateContactCreate)) { base.RegisteredEvents.Add(new Tuple&lt;int, string, string, Action&lt;LocalPluginContext&gt;&gt;(10, "Create", "contact", new Action&lt;LocalPluginContext&gt;(ExecutePreValidateContactCreate))); // Note : you can register for more events here if this plugin is not specific to an individual entity and message combination. // You may also need to update your RegisterFile.crmregister plug-in registration file to reflect any change. } /// &lt;summary&gt; /// Executes the plug-in. /// &lt;/summary&gt; /// &lt;param name="localContext"&gt;The &lt;see cref="LocalPluginContext"/&gt; which contains the /// &lt;see cref="IPluginExecutionContext"/&gt;, /// &lt;see cref="IOrganizationService"/&gt; /// and &lt;see cref="ITracingService"/&gt; /// &lt;/param&gt; /// &lt;remarks&gt; /// For improved performance, Microsoft Dynamics CRM caches plug-in instances. /// The plug-in's Execute method should be written to be stateless as the constructor /// is not called for every invocation of the plug-in. Also, multiple system threads /// could execute the plug-in at the same time. All per invocation state information /// is stored in the context. This means that you should not use global variables in plug-ins. /// &lt;/remarks&gt; protected void ExecutePreValidateContactCreate(LocalPluginContext localContext) { if (localContext == null) { throw new ArgumentNullException("localContext"); } // TODO: Implement your custom Plug-in business logic. Entity Contact = new Entity("contact"); Contact.Attributes["firstname"] = "SomeName"; Contact.Attributes["lastname"] = "SomeSurname"; service.Create(Contact); } } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload