-
Notifications
You must be signed in to change notification settings - Fork 14
Tutorial 9
PhuocLe edited this page Aug 27, 2018
·
12 revisions
- When a lead qualified, send an email (with an email template) notification to all team members of the current user belong to teams
- 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
- Finish Tutorial 7: Custom Action
- Finish Tutorial 8: Plugin and Unit Test Plugin
This tutorial is the combine of these tutorials: 5, 6, 7, 8 that make the final solution the customer want
- User create a new lead then send an email to all team members
- If user has security role "Qualify Lead", they can see the button "QUALIFY"
- User click button "QUALIFY", it create Account and Contact then redirect to Account created
- Process "QUALIFY" should copy field Field1, Field2, Field3 from lead to account
- When lead qualified then send an email to all team members
- Hide
4
button in theHomepage
ofLead
entityMscrm.HomepageGrid.lead.ConvertLeadAs
Mscrm.HomepageGrid.lead.ConvertLeadAs.Web
Mscrm.HomepageGrid.lead.ConvertLeadQuick
Mscrm.HomepageGrid.lead.ConvertLeadQuick.Web
- Hide
4
button in theForm
ofLead
entityMscrm.Form.lead.ConvertLeadAs
Mscrm.Form.lead.ConvertLeadAs.Web
Mscrm.Form.lead.ConvertLeadQuick
Mscrm.Form.lead.ConvertLeadQuick.Web
- Copy button
-
Mscrm.Form.lead.ConvertLeadAs
and paste as namepaz.Mscrm.Form.lead.ConvertLeadQuick
-
Mscrm.Form.lead.ConvertLeadQuick.Web
and paste as namepaz.Mscrm.Form.lead.ConvertLeadQuick.Web
-
- Edit
Customise Command
of2
buttonpaz.Mscrm.Form.lead.ConvertLeadQuick
,paz.Mscrm.Form.lead.ConvertLeadQuick.Web
- Add
enable rule
-
Id
:paz.lead.EnableRule.HasRole
- CustomRule
-
Default
:True
-
FunctionName
:isNaN
-
Library
:$webresource:paz_/lib/WebApiClient.js
-
- CustomRule
-
FunctionName
:formLead.HasRole
-
Library
:$webresource:paz_/entities/Lead.js
-
String Parameter
:Qualify Lead
-
-
- Add enable rule
paz.lead.EnableRule.HasRole
to2
commandMscrm.Form.lead.ConvertQuick
andMscrm.Form.lead.ConvertQuick.Web
- Edit
Actions
in2
commandMscrm.Form.lead.ConvertQuick
andMscrm.Form.lead.ConvertQuick.Web
-
Library
:$webresource:paz_/entities/Lead.js
-
Function Name
:formLead.QualifyLead_Click
- _
CRM Parameter
__:PrimaryControl
-
- Publish
- The
RibbonDiffXml
bellow
<?xml version="1.0" encoding="utf-16"?>
<RibbonDiffXml xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<CustomActions>
<CustomAction Id="paz.Mscrm.Form.lead.ConvertLeadQuick.CustomAction" Location="Mscrm.Form.lead.MainTab.Actions.Controls._children" Sequence="0">
<CommandUIDefinition>
<Button Alt="$LocLabels:Ribbon.Form.opportunity.MainTab.Actions.Convert" Command="Mscrm.Form.lead.ConvertQuick" Id="paz.Mscrm.Form.lead.ConvertLeadQuick" Image32by32="$webresource:MarketingSales/_imgs/ribbon/ConvertLead_32.png" Image16by16="$webresource:MarketingSales/_imgs/ribbon/ConvertLead_16.png" LabelText="$LocLabels:Ribbon.Form.opportunity.MainTab.Actions.Convert" Sequence="0" TemplateAlias="o1" ToolTipTitle="$LocLabels:Ribbon.Form.Lead.MainTab.Actions.Convert.ToolTipTitle" ToolTipDescription="$LocLabels:Ribbon.Tooltip.ConvertLead" ModernImage="Qualify" />
</CommandUIDefinition>
</CustomAction>
<CustomAction Id="paz.Mscrm.Form.lead.ConvertLeadQuick.Web.CustomAction" Location="Mscrm.Form.lead.MainTab.Actions.Controls._children" Sequence="0">
<CommandUIDefinition>
<Button Alt="$LocLabels:Ribbon.Form.opportunity.MainTab.Actions.Convert" Command="Mscrm.Form.lead.ConvertQuick.Web" Id="paz.Mscrm.Form.lead.ConvertLeadQuick.Web" Image32by32="$webresource:MarketingSales/_imgs/ribbon/ConvertLead_32.png" Image16by16="$webresource:MarketingSales/_imgs/ribbon/ConvertLead_16.png" LabelText="$LocLabels:Ribbon.Form.opportunity.MainTab.Actions.Convert" Sequence="0" TemplateAlias="o1" ToolTipTitle="$LocLabels:Ribbon.Form.Lead.MainTab.Actions.Convert.ToolTipTitle" ToolTipDescription="$LocLabels:Ribbon.Tooltip.ConvertLead" ModernImage="Qualify" />
</CommandUIDefinition>
</CustomAction>
<HideCustomAction HideActionId="paz.Mscrm.HomepageGrid.lead.ConvertLeadAs.Hide" Location="Mscrm.HomepageGrid.lead.ConvertLeadAs" />
<HideCustomAction HideActionId="paz.Mscrm.HomepageGrid.lead.ConvertLeadAs.Web.Hide" Location="Mscrm.HomepageGrid.lead.ConvertLeadAs.Web" />
<HideCustomAction HideActionId="paz.Mscrm.HomepageGrid.lead.ConvertLeadQuick.Hide" Location="Mscrm.HomepageGrid.lead.ConvertLeadQuick" />
<HideCustomAction HideActionId="paz.Mscrm.HomepageGrid.lead.ConvertLeadQuick.Web.Hide" Location="Mscrm.HomepageGrid.lead.ConvertLeadQuick.Web" />
<HideCustomAction HideActionId="paz.Mscrm.Form.lead.ConvertLeadQuick.Hide" Location="Mscrm.Form.lead.ConvertLeadQuick" />
<HideCustomAction HideActionId="paz.Mscrm.Form.lead.ConvertLeadQuick.Web.Hide" Location="Mscrm.Form.lead.ConvertLeadQuick.Web" />
<HideCustomAction HideActionId="paz.Mscrm.Form.lead.ConvertLeadAs.Hide" Location="Mscrm.Form.lead.ConvertLeadAs" />
<HideCustomAction HideActionId="paz.Mscrm.Form.lead.ConvertLeadAs.Web.Hide" Location="Mscrm.Form.lead.ConvertLeadAs.Web" />
</CustomActions>
<Templates>
<RibbonTemplates Id="Mscrm.Templates" />
</Templates>
<CommandDefinitions>
<CommandDefinition Id="Mscrm.Form.lead.ConvertQuick">
<EnableRules>
<EnableRule Id="Mscrm.LeadIsOpen" />
<EnableRule Id="Mscrm.Form.lead.IsUCI" />
<EnableRule Id="Mscrm.IsEntityAvailableForUserInMocaOffline" />
<EnableRule Id="Mscrm.IsAccountAvailableInMocaOffline" />
<EnableRule Id="Mscrm.IsContactAvailableInMocaOffline" />
<EnableRule Id="Mscrm.IsOpportunityAvailableInMocaOffline" />
<EnableRule Id="paz.lead.EnableRule.HasRole" />
</EnableRules>
<DisplayRules>
<DisplayRule Id="Mscrm.DynamicMenu.NewRecord.opportunity" />
<DisplayRule Id="Mscrm.HideOnOutlookClient" />
</DisplayRules>
<Actions>
<JavaScriptFunction FunctionName="formLead.QualifyLead_Click" Library="$webresource:paz_/entities/Lead.js">
<CrmParameter Value="PrimaryControl" />
</JavaScriptFunction>
</Actions>
</CommandDefinition>
<CommandDefinition Id="Mscrm.Form.lead.ConvertQuick.Web">
<EnableRules>
<EnableRule Id="Mscrm.LeadIsOpen" />
<EnableRule Id="Mscrm.Form.lead.IsNotUCI" />
<EnableRule Id="Mscrm.IsEntityAvailableForUserInMocaOffline" />
<EnableRule Id="Mscrm.IsAccountAvailableInMocaOffline" />
<EnableRule Id="Mscrm.IsContactAvailableInMocaOffline" />
<EnableRule Id="Mscrm.IsOpportunityAvailableInMocaOffline" />
<EnableRule Id="paz.lead.EnableRule.HasRole" />
</EnableRules>
<DisplayRules>
<DisplayRule Id="Mscrm.SingleQualifyStatusCode" />
<DisplayRule Id="Mscrm.DynamicMenu.NewRecord.opportunity" />
</DisplayRules>
<Actions>
<JavaScriptFunction FunctionName="formLead.QualifyLead_Click" Library="$webresource:paz_/entities/Lead.js">
<CrmParameter Value="PrimaryControl" />
</JavaScriptFunction>
</Actions>
</CommandDefinition>
</CommandDefinitions>
<RuleDefinitions>
<TabDisplayRules />
<DisplayRules>
<DisplayRule Id="Mscrm.DynamicMenu.NewRecord.opportunity">
<EntityPrivilegeRule PrivilegeType="Create" PrivilegeDepth="Basic" EntityName="opportunity" />
<EntityPrivilegeRule PrivilegeType="Append" PrivilegeDepth="Basic" EntityName="opportunity" />
<OrRule>
<Or>
<EntityPrivilegeRule PrivilegeType="AppendTo" PrivilegeDepth="Basic" EntityName="account" />
</Or>
<Or>
<EntityPrivilegeRule PrivilegeType="AppendTo" PrivilegeDepth="Basic" EntityName="contact" />
</Or>
</OrRule>
</DisplayRule>
<DisplayRule Id="Mscrm.HideOnOutlookClient">
<CrmClientTypeRule Type="Outlook" InvertResult="true" />
</DisplayRule>
<DisplayRule Id="Mscrm.SingleQualifyStatusCode">
<OptionSetRule OptionSet="lead_statuscode" StateCode="1" ObjectTypeCode="4" />
</DisplayRule>
</DisplayRules>
<EnableRules>
<EnableRule Id="Mscrm.LeadIsOpen">
<FormStateRule State="Existing" />
</EnableRule>
<EnableRule Id="Mscrm.Form.lead.IsUCI">
<CustomRule FunctionName="ClientUtility.ClientUtil.isUCI" Library="$webresource:MarketingSales/Lead/Lead_main_system_library.js" />
</EnableRule>
<EnableRule Id="Mscrm.IsEntityAvailableForUserInMocaOffline">
<CustomRule FunctionName="XrmCore.Rules.Online.IsEntityAvailableForUserInMocaOffline" Library="$webresource:Main_system_library.js">
<CrmParameter Value="SelectedEntityTypeName" />
</CustomRule>
</EnableRule>
<EnableRule Id="Mscrm.IsAccountAvailableInMocaOffline">
<CustomRule FunctionName="XrmCore.Rules.Online.IsEntityAvailableForUserInMocaOffline" Library="$webresource:Main_system_library.js">
<StringParameter Value="account" />
</CustomRule>
</EnableRule>
<EnableRule Id="Mscrm.IsContactAvailableInMocaOffline">
<CustomRule FunctionName="XrmCore.Rules.Online.IsEntityAvailableForUserInMocaOffline" Library="$webresource:Main_system_library.js">
<StringParameter Value="contact" />
</CustomRule>
</EnableRule>
<EnableRule Id="Mscrm.IsOpportunityAvailableInMocaOffline">
<CustomRule FunctionName="XrmCore.Rules.Online.IsEntityAvailableForUserInMocaOffline" Library="$webresource:Main_system_library.js">
<StringParameter Value="opportunity" />
</CustomRule>
</EnableRule>
<EnableRule Id="Mscrm.Form.lead.IsNotUCI">
<CustomRule FunctionName="ClientUtility.ClientUtil.isUCI" Library="$webresource:MarketingSales/Lead/Lead_main_system_library.js" InvertResult="true" />
</EnableRule>
<EnableRule Id="paz.lead.EnableRule.HasRole">
<CustomRule FunctionName="isNaN" Library="$webresource:paz_/lib/WebApiClient.js" Default="true" />
<CustomRule FunctionName="formLead.HasRole" Library="$webresource:paz_/entities/Lead.js">
<StringParameter Value="Qualify Lead" />
</CustomRule>
</EnableRule>
</EnableRules>
</RuleDefinitions>
<LocLabels />
</RibbonDiffXml>
- Create function
QualifyLead_Click
...
function qualifyLead_Click(executionContext) {//executionContext is PrimaryControl parameter use in the Riibon Workbench
var form = new LuckeyMonkey.FormLead(executionContext);
var input = {
LeadId: form.EntityId
};
var jsonInput = JSON.stringify(input);
var req = new LuckeyMonkey.WebApi.CustomRequest();
req.async = false;
req.method = "POST";
req.bound = false;
req.name = "paz_Ajax";
req.payload = {
"function": "QualifyLead",
"jsonInput": jsonInput
};
var res = WebApiClient.Execute(req);
var output = JSON.parse(res.jsonOutput);
if (output.Status) {
form.Utility.OpenForm({
entityName: "account",
entityId: output.AccountId
}, null, null, null);
}
}
return {
OnLoad: onLoad,
OnSave: onSave,
HasRole: hasRole,
QualifyLead_Click: qualifyLead_Click,
__SubjectAddOnChange__: SubjectAddOnChange,
__PhoneAddOnChange__: PhoneAddOnChange
};
...
NOTED
Please DON'T
copy/paste code. Try typing
to get intellisense
that PL.DynamicsCrm.DevKit
support
- Right-click on Visual Studio of file
Lead.js
then selectPL.DynamicsCrm.DevKit - Publish WebResource
and waitingPL.DynamicsCrm.DevKit
deployLead.js
to Dynamics 365 - Run
deploy.bat
of projectPaz.LuckeyMonkey.Workflow
- Create an
email template type
:Lead
withTitle
:Lead - Qualified Lead
- Create a
real-time workflow
nameLead - Qualified Lead
to use 2 custom workflowPaz.LuckeyMonkey.Workflow.RetrieveUsers
andPaz.LuckeyMonkey.Workflow.SendUsersMail
- Configure current user has security role
Qualify Lead
- Configure current user belong to teams:
Sales
andIT
- Current user create a new lead -> check all team members received an email
Lead - New Lead
- Current user open lead just created and see the button
QUALIFY
- Current user click on button
QUALIFY
, system do a qualify process, createAccount
andContact
then redirect user toAccount
just created - Check all team members received an email
Lead - Qualified Lead
- Check 3 fields in
Account
that have copied fromLead
This tutorial, you know howto
- Use simple
Ribbon Workbench
- Reference library in
Ribbon Workbench
by using functionisNaN
- Form
Javascript
callCustom Action
to Dynamics 365