Skip to content

Tutorial 3

PhuocLe edited this page Aug 26, 2018 · 8 revisions

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

Coding

  1. Add New Project 05. C# WebResource Project to your solution
    • A popup form Add new WebResource Project opened
    • Click button >< to create/select a Dynamics 365 connection
    • After connected, click OK
    • PL.DynamicsCrm.DevKit created project name: Paz.LuckeyMonkey.WebResource
  2. Rebuild solution to restore NuGet packages
  3. Open file PL.DynamicsCrm.DevKit.Cli.json by Notepad and edit these information in section: webresources.profile = "DEBUG"
    • webresources.solution = "LuckeyMonkey"
    • webresources.prefix = "paz_"
  4. Open file PL.DynamicsCrm.DevKit.json by Notepad and edit
    • SolutionPrefix = "paz_"
  5. Add New Item 07. JavaScript Form to entities folder of Paz.LuckeyMonkey.WebResource project
    • A popup form Add new Js Form Class opened
    • Click button >< to create/select a Dynamics 365 connection
    • After connected PL.DynamicsCrm.DevKit loaded all entities and bind to dropdown Entity
    • Select Lead in the Entity then click Load Forms button
    • Select Lead in the list checkbox (This list load all forms Lead)
    • Click OK
  6. PL.DynamicsCrm.DevKit created 3 JavaScript files
    • Lead.js write your JavaScript code here, deploy this file to Dynamics 365
    • Lead.form.js DON'T changes this file, it will be lost when you re-generate, deploy this file to Dynamics 365
    • Lead.intellisense.js DON'T changes this file, it will be lost when you re-generate. DON'T deploy this file to Dynamics 365
  7. If you are using Visual Studio 2017 please turn off Enable the new JavaScript language service in the Tools -> Options -> Text Editor -> JavaScript/TypeScript -> Language Service and restart Visual Studio
  8. Open Lead.js and begin coding. Please DON'T copy/paste code. Try typing to get intellisense that PL.DynamicsCrm.DevKit support
///<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
	};
})();
  1. Open Lead Form design. Click Form Properties
    • Add library: paz_/entities/Lead.form.js to section: Form Libraries
    • Add library: paz_/entities/Lead.js to section: Form Libraries
    • Add function formLead.OnLoad of library paz_/entities/Lead.js to section Event Handlers. Make sure you checked Pass execution context as first parameter
  2. Save then Publish form
  3. Go to Dynamics 365, create/edit Lead and check your task
  4. Check-in all files to your source control
  5. You finished this tutorial

Summary

This tutorial, you know howto

Clone this wiki locally