Skip to content

Instantly share code, notes, and snippets.

View DynCon365's full-sized avatar

Dynamic Consulting DynCon365

View GitHub Profile
@DynCon365
DynCon365 / gist:6736377081cbbbb4201adf60eceb6e2f
Created August 11, 2020 21:24
Dynamics 365/CRM 9.0+ | Get the value of a bit field
//-------------------------------------------------------------------------------------------
// getBitField
//-------------------------------------------------------------------------------------------
function getBitField(e) {
// Get the value of a custom "Is Decision Maker" checkbox on a Contact
var decisionMaker = formContext.getAttribute("new_isDecisionMaker").getValue();
// checked will return 1; unchecked will return 0;
@DynCon365
DynCon365 / gist:cb424bfc22dbcd9d5fc84a8fea3a030c
Created August 11, 2020 21:23
Dynamics 365/CRM 9.0+ | Set the value of a numeric field
//-------------------------------------------------------------------------------------------
// setNumericField
//-------------------------------------------------------------------------------------------
function setNumericField(e){
// Get the Form Context
var formContext = e.getFormContext();
// Set the Contact's age to 25
@DynCon365
DynCon365 / gist:fdb5eeb911ca832971e2c3f4353026c4
Created August 11, 2020 21:22
Dynamics 365/CRM 9.0+ | Get the value of a numeric field
//-------------------------------------------------------------------------------------------
// getNumericField
//-------------------------------------------------------------------------------------------
function getNumericField(e){
// Get the Form Context
var formContext = e.getFormContext();
// Get the value of a custom Age field on a Contact
@DynCon365
DynCon365 / gist:989424714ee2b23f167d2811f9c0d6ea
Created August 11, 2020 21:21
Dynamics 365/CRM 9.0+ | Set the value of a lookup field
//-------------------------------------------------------------------------------------------
// setLookupField
//-------------------------------------------------------------------------------------------
function setLookupField(e){
// Get the Form Context
var formContext = e.getFormContext();
// First, you need the GUID, Name and Entity Type stored as variables
@DynCon365
DynCon365 / gist:636c0c7df69c85c906318a4c8033c710
Created August 11, 2020 21:20
Dynamics 365/CRM 9.0+ | Get the text of a lookup field
//-------------------------------------------------------------------------------------------
// getLookupFieldText
//-------------------------------------------------------------------------------------------
function getLookupFieldText(e){
// Get the Form Context
var formContext = e.getFormContext();
// Get the Parent Company name of a Contact
@DynCon365
DynCon365 / gist:313addc0c98bd2d624dfd997d2f56670
Created August 11, 2020 21:18
Dynamics 365/CRM 9.0+ | Set the value of a text field
//-------------------------------------------------------------------------------------------
// setTextField
//-------------------------------------------------------------------------------------------
function setTextField(e){
// Get the Form Context
var formContext = e.getFormContext();
// Set the Contact's first name to Joe
@DynCon365
DynCon365 / gist:6d8aba4db942861244006f8c2875d3f7
Last active August 11, 2020 21:14
Dynamics 365/CRM 9.0+ | Get the value of a text field
//-------------------------------------------------------------------------------------------
// getTextField
//-------------------------------------------------------------------------------------------
function getTextField(e){
// Get the Form Context
var formContext = e.getFormContext();
// Get the value of a Contact's first name
@DynCon365
DynCon365 / gist:a7c2e41edb9ec551f2e995e95e0f4660
Last active April 4, 2018 20:40
Dynamics 365/CRM | Show/hide form fields
// Consider using Business Rules before using this code
// Show a form field
Xrm.Page.ui.controls.get("new_formField").setVisible(true);
// Hide a form field
Xrm.Page.ui.controls.get("new_formField").setVisible(false);
@DynCon365
DynCon365 / gist:61a412a23c8b7f694a7f70497b28687f
Last active April 4, 2018 20:24
Dynamics 365/CRM | Get the value of an Option Set
// Get the value of the Opportunity Status Reason field
var statusReason = Xrm.Page.data.entity.attributes.get("statuscode").getValue();
@DynCon365
DynCon365 / gist:f31b6dc41faa9ffe9795c879b603ab2f
Last active April 4, 2018 20:21
Dynamics 365/CRM | Get the text of an Option Set
// Get the text of the Opportunity Status Reason field
var statusReason = Xrm.Page.data.entity.attributes.get("statuscode").getText();