Örnegin,teklif yaratırken hem teklif üzerinden hem firsat üzerinden teklif yaratırız.Teklif create için plugin yazdıysak bunun hangi create anında calısmasını plugin registor tool üzerinden vermemız gerekır.
İlk Senaryo :
Sales->Quotes->New (Teklif üzerinden teklif yaratma)
PLugin Code
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Crm.Sdk;
using Microsoft.Crm.Sdk.Query;
using Microsoft.Crm.SdkTypeProxy;
using Microsoft.Crm.SdkTypeProxy.Metadata;
using Microsoft.Crm.Sdk.Metadata;
using System.Web.Services;
using Microsoft.Win32;
namespace TestQuotePlugin
{
public class QuotePlugin : IPlugin
{
public void Execute(IPluginExecutionContext context)
{
ICrmService crmService = (ICrmService)context.CreateCrmService(true);
IMetadataService metaData = context.CreateMetadataService(true);
lead ld = new lead();
ld.subject = "Test Subject";
ld.firstname = "Test FirstName";
ld.lastname = "Test LastName";
ld.companyname = "Test Company";
crmService.Create(ld);
}
}
}
Bu sekılde olustugunda fırsat üzerinden teklif yaratılınca plugin calısmayacaktır.
İkinci senaryo : Sales->Opportunity->(Open Opportunity)->Quotes->New Quote
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Crm.Sdk;
using Microsoft.Crm.Sdk.Query;
using Microsoft.Crm.SdkTypeProxy;
using Microsoft.Crm.SdkTypeProxy.Metadata;
using Microsoft.Crm.Sdk.Metadata;
using System.Web.Services;
using Microsoft.Win32;
namespace TestQuotePlugin
{
public class QuotePlugin : IPlugin
{
public void Execute(IPluginExecutionContext context)
{
CrmService crmService = CreateCrmService(context);
lead ld = new lead();
ld.subject = "Test Subject";
ld.firstname = "Test FirstName";
ld.lastname = "Test LastName";
ld.companyname = "Test Company";
crmService.Create(ld);
}
private static CrmService CreateCrmService(IPluginExecutionContextcontext)
{
CrmAuthenticationToken token = new CrmAuthenticationToken();
token.AuthenticationType = AuthenticationType.AD;
token.OrganizationName = context.OrganizationName;
CrmService crmService = new CrmService();
crmService.UseDefaultCredentials = true;
crmService.Url = (string)(Registry.LocalMachine.OpenSubKey("Software\\Microsoft\\MSCRM").GetValue("ServerUrl")) + "/2007/crmservice.asmx";
crmService.CrmAuthenticationTokenValue = token;
return crmService;
}
}
}