-
Notifications
You must be signed in to change notification settings - Fork 15
Tutorial 8
PhuocLe edited this page Mar 8, 2018
·
7 revisions
- Automatic create Contact record when Account created with these mapping
- Contact First Name = Account Name
- Contact Telephone1 = Account Telephone 1
- Contact Address Type 1 always Other
- Add
08. C# Plugin Class
toWooow.Kool.Plugin.Account
project- Message:
Create
- Stage:PostOperation
- Execution:Synchronous
-
PL.DynamicsCrm.DevKit
created plugin class:PostAccountCreateSynchronous
- Message:
- Add
21. C# Late Bound Class
Contact
toEntities
folder ofWooow.Kool.Shared
project.-
PL.DynamicsCrm.DevKit
created 2 files:Contact.js
andContact.generated.cs
-
- Add
PL.DynamicsCrm.DevKit
>C# Date.cs
toLib
folder ofWooow.Kool.Shared
project. - Rebuild solution without errors.
- Continue coding
public override void Execute()
{
if (Plugin.Context.Stage != (int)StageEnum.PostOperation) throw new InvalidPluginExecutionException("Stage does not equals PostOperation");
if (Plugin.Context.PrimaryEntityName != "account") throw new InvalidPluginExecutionException("PrimaryEntityName does not equals account");
if (Plugin.Context.MessageName.ToLower() != "Create".ToLower()) throw new InvalidPluginExecutionException("MessageName does not equals Create");
if (Plugin.Context.Mode != (int)ExecutionModeEnum.Synchronous) throw new InvalidPluginExecutionException("Execution does not equal Synchronous");
var target = (Entity)Plugin.Context.InputParameters["Target"];
//var preEntity = (Entity)Plugin.Context.PreEntityImages["PreImage"];
//var postEntity = (Entity)Plugin.Context.PreEntityImages["PostImage"];
//YOUR PLUGIN-CODE GO HERE
var account = new Account(target);
var contact = new Contact();
contact.ParentCustomerId = new EntityReference(Account.EntityLogicalName, account.Id);
contact.FirstName = account.Name;
contact.Telephone1 = account.Telephone1;
contact.Address1_AddressTypeCode = Address1_AddressTypeCode.Other;
Plugin.Service.Create(contact.GetCreateEntity());
}
- Run
deploy.bat
inWooow.Kool.Plugin.Account
to deploy plugin. - Go to Dynamics Crm, create new Account to check plugin worked or not.
- Check-in all files to your source control.
- You finished this tutorial.
Your Solution Explorer
after you finished this tutorial