1. Open visual studio >> new Project >>Dynamics CRM(in 'installed templates' - left side navigation) >> Dynamics CRM 2011 Package.
name : my first plugin
If there is no Dynamics CRM in Installed Template , then install the crmdevelopertools_installer.msi(present in crm sdk >> tools >> developertoolkit).
2. Fill-up the required credentials : user-name , password , organisation , discovery url , solution.
3.Add a new project then add crm plugin in it

4. Generate "Entities.cs" class by using "generate wrapper" from the CRM explorer .
5. Create plugin using the CRM Explorer ,
6. Add :
using Microsoft.Xrm.Sdk.client;
using Entities;"
these all namespaces to "PostAccountCreate.cs" .
7. Add this code after
// TODO: Implement your custom Plug-in business logic.
IPluginExecutionContext context = localContext.PluginExecutionContext;
IOrganizationService service = localContext.OrganizationService;
var ServiceContext = new OrganizationServiceContext(service);
if(context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
{
Entity account = (Entity)context.InputParameters["Target"] ;
try
{
if (account != null)
{
if (account.LogicalName == "account")
{
account.Attributes.Add("new_testname", "yes data gets inserted");
account["new_testids"] = "1298";
if (!ServiceContext.IsAttached(account))
{
ServiceContext.Attach(account);
}
ServiceContext.UpdateObject(account);
ServiceContext.SaveChanges();
}
}
}
catch (Exception ex)
{
new InvalidPluginExecutionException("here is the error", ex);
}
}
8. Create a (.snk file) strong name key file .
9. Build the solution .
10. Deploy the solution .









No comments:
Post a Comment