-
Notifications
You must be signed in to change notification settings - Fork 15
Tutorial 7
PhuocLe edited this page Aug 27, 2018
·
7 revisions
- Qualify lead don't create Opportunity, create Account and move to Account page after success qualified
- Finish Tutorial 1: Plugin
- Finish Tutorial 2: Unit Test Plugin
- Finish Tutorial 3: WebResource
- Finish Tutorial 4: Unit Test WebResource
- Finish Tutorial 5: Custom Workflow
- Finish Tutorial 6: WebApiClient
- Goto Dynamics 365, create a
Custom Action
thenActivated
with these information bellow
-
Process Name
:Ajax
-
Unique Name
:paz_Ajaz
-
Entity
:None (global)
-
Arguments
-
Name
:function
,Type
:String
,Required
:Required
,Direction
:Input
-
Name
:jsonInput
,Type
:String
,Required
:Optional
,Direction
:Input
-
Name
:jsonOutput
,Type
:String
,Required
:Required
,Direction
:Output
-
- Add
New Project
02. C# Custom Action Project
to solution.- A popup form
Add new Custom Action Project
opened - Click button
><
to create/select a Dynamics 365 connection - Keep the text box
Project Name
empty - Select
9.0.2.4
in theCrm Version
PL.DynamicsCrm.DevKit
get allMicrosoft.CrmSdk.CoreAssemblies
version fromNuGet
- Select
4.5.2
in the.Net version
- Click
OK
-
PL.DynamicsCrm.DevKit
created workflow project name:Paz.LuckeyMonkey.CustomAction
- A popup form
- Rebuild solution to restore
NuGet
packages - Add
New Item
04. C# Custom Action Class
toPaz.LuckeyMonkey.CustomAction
project- A popup form opened
- Click button
><
to create/select a Dynamics 365 connection - After connected
PL.DynamicsCrm.DevKit
loaded all entities and bind to dropdownMessage
- Select
paz_Ajax
- Click
OK
-
PL.DynamicsCrm.DevKit
created custom action class:PostNonepaz_AjaxSynchronous
- Edit
ExecuteCustomAction
like bellow
private ParameterCollection ExecuteCustomAction(IPluginExecutionContext context, IOrganizationServiceFactory serviceFactory, IOrganizationService service, ITracingService tracing)
{
var outputs = new ParameterCollection();
//YOUR CUSTOM ACTION BEGIN HERE
var function = (string)context.InputParameters["function"];
var jsonInput = (string)context.InputParameters["jsonInput"];
var @return = string.Empty;
switch (function)
{
case "QualifyLead":
var qualifyLead = new QualifyLead();
@return = qualifyLead.Do(context, service, tracing, jsonInput);
break;
}
outputs.Add(new KeyValuePair<string, object>("jsonOutput", @return));
return outputs;
}
- Class
QualifyLead
public class InputQualifyLead
{
public string LeadId { get; set; }
}
public class OutputQualifyLead
{
public string AccountId { get; set; }
public bool Status { get; set; }
}
public class QualifyLead
{
internal string Do(IPluginExecutionContext context, IOrganizationService service, ITracingService tracing, string jsonInput)
{
//Parse jsonInput to strong type InputQualifyLead
var input = SimpleJson.DeserializeObject<InputQualifyLead>(jsonInput);
//Call request QualifyLead
var request = new QualifyLeadRequest()
{
CreateAccount = true,
CreateOpportunity = false,
CreateContact = true,
LeadId = new EntityReference(Lead.EntityLogicalName, Guid.Parse(input.LeadId)),
Status = new OptionSetValue((int)StatusCode.Qualified)
};
var response = (QualifyLeadResponse)service.Execute(request);
var account = response.CreatedEntities.FirstOrDefault(r => r.LogicalName == Account.EntityLogicalName);
//Prepare output and Serialize to jsonOutput
var output = new OutputQualifyLead
{
Status = account != null,
AccountId = account?.Id.ToString()
};
return SimpleJson.SerializeObject(output);
}
}
NOTED
You should add 01. C# Late Bound Class
class: Account
to Entities
folder of Paz.LuckeyMonkey.Shared
project
- Run
deploy.bat
of projectPaz.LuckeyMonkey.CustomAction
- Check-in all files to your source control
- You finished this tutorial
This tutorial, you know howto