Tutorial 3 - phuocle/Dynamics-Crm-DevKit GitHub Wiki
Task
- When creating lead, topic field always uppercase. But when editing, it cannot edit
- When creating/editing lead, if user enter Business Phone they should be enter Mobile Phone too and vice versa. Otherwise, 2 fields can be blank
Prerequisites
- Finish Tutorial 1
- Finish Tutorial 2
Coding
- Add
New Project05. C# WebResource Projectto your solution- A popup form
Add new WebResource Projectopened - Click button
><to create/select a Dynamics 365 connection - After connected, click
OK PL.DynamicsCrm.DevKitcreated project name:Paz.LuckeyMonkey.WebResource
- A popup form
- Rebuild solution to restore
NuGetpackages - Open file
PL.DynamicsCrm.DevKit.Cli.jsonby Notepad and edit these information in section:webresources.profile = "DEBUG"webresources.solution = "LuckeyMonkey"webresources.prefix = "paz_"
- Open file
PL.DynamicsCrm.DevKit.jsonby Notepad and editSolutionPrefix = "paz_"
- Add
New Item07. JavaScript Formtoentitiesfolder ofPaz.LuckeyMonkey.WebResourceproject- A popup form
Add new Js Form Classopened - Click button
><to create/select a Dynamics 365 connection - After connected
PL.DynamicsCrm.DevKitloaded all entities and bind to dropdownEntity - Select
Leadin theEntitythen clickLoad Formsbutton - Select
Leadin the list checkbox (This list load all formsLead) - Click
OK
- A popup form
PL.DynamicsCrm.DevKitcreated3JavaScript filesLead.jswrite your JavaScript code here,deploythis file to Dynamics 365Lead.form.jsDON'Tchanges this file, it will be lost when you re-generate,deploythis file to Dynamics 365Lead.intellisense.jsDON'Tchanges this file, it will be lost when you re-generate.DON'Tdeploythis file to Dynamics 365
- If you are using
Visual Studio 2017pleaseturn offEnable the new JavaScript language servicein theTools->Options->Text Editor->JavaScript/TypeScript->Language Serviceand restartVisual Studio - Open
Lead.jsand begin coding. PleaseDON'Tcopy/paste code. Trytypingto getintellisensethatPL.DynamicsCrm.DevKitsupport
///<reference path='Lead.intellisense.js' />
var formLead = (function () {
function onLoad(executionContext) {
var form = new LuckeyMonkey.FormLead(executionContext);
if (form.FormType !== OptionSet.FormType.Create) {
form.Body.Subject.Disabled = true;
}
else {
form.Body.Subject.AddOnChange(SubjectAddOnChange);
}
form.Body.Telephone1.AddOnChange(PhoneAddOnChange);
form.Body.MobilePhone.AddOnChange(PhoneAddOnChange);
}
function onSave(executionContext) {
}
function SubjectAddOnChange(executionContext) {
var form = new LuckeyMonkey.FormLead(executionContext);
if (form.Body.Subject.Value !== null) {
form.Body.Subject.Value = form.Body.Subject.Value.toUpperCase();
}
}
function PhoneAddOnChange(executionContext) {
var form = new LuckeyMonkey.FormLead(executionContext);
if (form.Body.Telephone1.Value !== null ||
form.Body.MobilePhone.Value !== null) {
form.Body.Telephone1.RequiredLevel = OptionSet.FieldRequiredLevel.Required;
form.Body.MobilePhone.RequiredLevel = OptionSet.FieldRequiredLevel.Required;
}
else {
form.Body.Telephone1.RequiredLevel = OptionSet.FieldRequiredLevel.None;
form.Body.MobilePhone.RequiredLevel = OptionSet.FieldRequiredLevel.None;
}
}
return {
OnLoad: onLoad,
OnSave: onSave
};
})();
- Open
Lead Formdesign. ClickForm Properties- Add library:
paz_/entities/Lead.form.jsto section:Form Libraries - Add library:
paz_/entities/Lead.jsto section:Form Libraries - Add function
formLead.OnLoadof librarypaz_/entities/Lead.jsto sectionEvent Handlers. Make sure you checkedPass execution context as first parameter
- Add library:
SavethenPublishform- Go to Dynamics 365, create/edit
Leadand check your task - Check-in all files to your source control
- You finished this tutorial
Summary
This tutorial, you know howto
- Add
05. C# WebResource Project - Add
07. JavaScript Form - Config
PL.DynamicsCrm.DevKit.Cli.jsonforWebResource - Config
PL.DynamicsCrm.DevKit.jsonfordeployjavascriptfromVisual Studio