JavaScript – Refresh Forms

Here is a quick JavaScript code example. Having added a new opportunity on a contact I wanted to refresh the contact form and at the same time save any changes. This concept might be useful in several circumstances, say you have a customization on the opportunity that updates fields on the contact. Then refreshing the…

Javascript – Set any value

Previously I have shown standard functions I use to get text values of attributes and set option sets based on their text value. Here is another common function I use to set the value of any field.(Except lookups which need more parameters, I will cover these later!) // *** FUNCTION : SetValue // *** PARAMS…

JavaScript – Basics

Microsoft Dynamics CRM allows the addition of JavaScript to forms which enables the extension of the basic solution in many ways. CRM Developers and customizers make extensive use of this when tailoring CRM systems to meet customer requirements. The web is littered with many people publishing useful code snippets which with very little JavaScript knowledge…

JavaScript – getSaveMode

Quick post, hopefully useful reference material …. getSaveMode(), returns a value indicating how the save event was initiated. execObj.getEventArgs().getSaveMode() Note: Don’t forget that you will need to tick the option to return the context as the first parameter on your on-save event. Entity Event Mode Value All Save 1 All Save and Close 2 All Save…

Javascript – Set Lookup Details

In previous posts I describe some common functions I use to get field text values, set optionset values from text, set text field values etc. Here is another post containing a standard functions to set lookup values; // *** FUNCTION: SetLookUp // *** PARAMS: // *** fieldName = The name of the lookup field //…

Javascript – getFormType

Quick post, hopefully useful for reference ….., getFormType() The getForType method is used to get the form context. The following table lists the form types that correspond to the return value. Xrm.Page.ui.getFormType(); Form Type Value Undefined 0 Create 1 Update 2 Read Only 3 Disabled 4 Quick Create 5 Bulk Edit 6 Read Optimized 11

Javascript – Prevent Save

From time to time you might need to add some validation to the save event of an entity, this actually used to be an approach I would use on a regular basis but since the introduction of business rules have found myself doing this less and less. But still, knowing the ability is available is…

Javascript – Notifications

It is possible (and now supported) to show notifications on CRM forms, use the following code to show notifications. Xrm.Page.ui.setFormNotification(<<Message>>, <<Level>>, <<uniqueId>>);   Xrm.Page.ui.setFormNotification(“Give some Info!”, “INFO”, “1”); Xrm.Page.ui.setFormNotification(“Give a warning!”, “WARNING”, “2”); Xrm.Page.ui.setFormNotification(“Give an error!”, “ERROR”, “3”);   The notifications will look like this …. You can also remove a notification using the command below;…

Javascript – Return Roles

Here is an example of the code needed in Microsoft Dynamics CRM 2015 to return the roles for the current user. function onLoad() { // ** Shows all the roles for current user var Roles = Xrm.Page.context.getUserRoles(); for (var i = 0; i < Roles.length; i++) { var RoleId = Roles[i]; var selectQuery = “/RoleSet?$top=1&$filter=RoleId…