Skip to content

Tutorial 3

PhuocLe edited this page Aug 24, 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 5. 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. Add New Item 7. 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
  5. 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
  6. 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
  7. Open Lead.js and begin coding the task.
///<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
	};
})();
Clone this wiki locally