Tag Archives: Javascript

Create a Rich-Text textarea in Microsoft CRM 2013 forms

ckeditor sample

Sometimes there is a need for creating HTML content within an entity. There are many websites with a how-to description, but be careful: most of them are unsupported! You can easily recognize those solutions. Whenever you find a javascript code which uses something like “document.getElementById()” or uses jquery to get or change attributes on a crm form … hands off. This is unsupported and might be a problem the next time you install an update rollup or upgrade to a new major release.

But it is very simple to build a rich text element. Here is an easy walktrough:

1) Identify the field you want to store the HTML code into. Best practice is to use a memo field, large enough to hold the whole content. You can use for example the description field in the contact entity, or something similar.

2) Download a free WYSIWYG editor. Personally I find the best choice is ckeditor, but you can use almost any other. You can download ckeditor from this site.

3) Create a html-webresource with more or less this content:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script src="../../ckeditor_/ckeditor/ckeditor.js"></script>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>

    <script type="text/javascript">
        CKEDITOR.timestamp = null;
        var Xrm;

        $(document).ready(function () {

            var Xrm = parent.Xrm;
            var voeb_eckdaten = Xrm.Page.getAttribute("description").getValue();
            document.getElementById('editor1').value = voeb_eckdaten;

            CKEDITOR.instances.editor1.on('blur', function () {
                var value = CKEDITOR.instances.editor1.getData();
                Xrm.Page.getAttribute("description").setValue(value);
            });

        });

    </script>
</head>
<body>
    <textarea class="ckeditor" cols="80" id="editor1" name="editor1" rows="10"></textarea>
</body>
</html>

In this example I used the description field for editing. This means of course you must have the field somewhere on the form.
What this code does is:
* wait until the document is in ready state
* get the content of the description field
* initialize ckeditor

It took me some time to recognize that ckeditor uses a parameter to avoid being cached, but if you leave the timestamp property on, crm will throw an error (500 server error). I disabled the timestamp setting the property to null.
ckeditor sample

So if you would like to use this in your crm deployment I added a solution with the complete ckeditor. I suggest to use a managed solution in your production environment, so if you want to get rid of ckeditor all you have to do is to uninstall the solution.

download unmanaged
download managed

Leave a Reply

Your email address will not be published. Required fields are marked *


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Microsoft Dynamics CRM 2013 Xrm.Page.ui.formSelector

formSelector

The Xrm.Page.ui.formSelector contains an items collection that provides capabilities to query the forms available for the current user.

formSelector.getCurrentItem

Method to return a reference to the form currently being shown.

When only one form is available this method will return null.

formSelector.items

A collection of all the form items accessible to the current user.

Only those forms that share an association with one of the user’s security roles are available in this collection.

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Microsoft Dynamics CRM 2013 Client-side context

getContext

context = eContext.getContext();

getClient

Returns a value to indicate which client the script is executing in.

context.client.getClient();
Client Value
Browser Web
Outlook Outlook
Mobile Mobile

getClientState

Returns a value to indicate the state of the client.

Use this instead of the deprecated isOutlookOnline method.

context.client.getClientState();
Client Valid Clients
Online Web, Outlook, Mobile
Offline Outlook, Mobile

getClientUrl

Returns the base URL that was used to access the application.

Use this instead of the deprecated getServerUrl method.

context.getClientUrl();
Client Value
Microsoft Dynamics CRM (on-premises) http(s)://server/org
Microsoft Dynamics CRM Online https://org.crm.dynamics.com
Microsoft Dynamics CRM for Outlook with Offline Access when offline http://localhost:2525

getCurrentTheme

Returns a string representing the current Microsoft Office Outlook theme chosen by the user.

context.getCurrentTheme();
Value Theme
default Microsoft Dynamics CRM web application
Office12Blue Microsoft Dynamics CRM for Outlook 2007 or 2010 Blue Theme
Office14Silver Microsoft Dynamics CRM for Outlook 2007 or 2010 Silver or Black Theme

getOrgLcid

Returns the LCID value that represents the base language for the organization

context.getOrgLcid();

Vaild locale ID values can be found at Locale ID Chart.

The most needed:

English … 1033
French … 1036
German … 1031

getOrgUniqueName

Returns the unique text value of the organization’s name.

context.getOrgUniqueName();

getQueryStringParameters

Returns a dictionary object of key value pairs that represent the query string arguments that were passed to the page.

context.getQueryStringParameters();

getUserId

Returns the GUID of the SystemUser.Id value for the current user.

context.getUserId();

getUserLcid

Returns the LCID value that represents the Microsoft Dynamics CRM Language Pack that is the user selected as their preferred language.

context.getUserLcid();

Vaild locale ID values can be found at Locale ID Chart.

getUserName

Returns the name of the current user.

context.getUserName();

This method is only available for Updated Entities.

getUserRoles

Returns an array of strings that represent the GUID values of each of the security roles that the user is associated with or any teams that the user is associated with.

context.getUserRoles();

prependOrgName

Prepends the organization name to the specified path.

context.prependOrgName(sPath);

The value returned follows this pattern: “/”+ OrgName + sPath

Leave a Reply

Your email address will not be published. Required fields are marked *


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Microsoft Dynamics CRM 2013 Prevent a record from being saved

function My_PreventSaveFunction(eContext) {
 eContext.getEventArgs().preventDefault();
}

This method is essential if you want to enable auto-save for most forms in an organization but disable it for specific forms. The following code registered for the onSave event with the execution context passed to it will prevent any saves that initiate from an auto-save but allow all others.

With auto-save enabled, navigating away is equivalent to Save and Close. This code will prevent any saves that are initiated by the 30 second timer or when people navigate away from a form with unsaved data.

function preventAutoSave(econtext) {
    var eventArgs = econtext.getEventArgs();
    if (eventArgs.getSaveMode() == 70 || eventArgs.getSaveMode() == 2) {
        eventArgs.preventDefault();
    }
}

You can even check if  the save event has been canceled because the preventDefault method was used in this event hander or a previous event handler:

econtext.getEventArgs().isDefaultPrevented()

Leave a Reply

Your email address will not be published. Required fields are marked *


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Microsoft Dynamics CRM 2013 Save Event Arguments

Entity Event Mode Value
All Save 1
All Save and Close 2
All Save and New 59
All AutoSave 70
Activities Save as Completed 58
All Deactivate 5
All Reactivate 6
User or Team owned entities Assign 47
Email (E-mail) Send 7
Lead Qualify 16
Lead Disqualify 15

 

Below you find an example from the SDK RC to show all the available save modi:

function My_GetSaveModeTextFunction(eContext) {
 var saveModeCode = eContext.getEventArgs().getSaveMode();
 var saveModeText = "Unknown";
 switch (saveModeCode) {
  case 1:
   saveModeText = "Save";
   break;
  case 2:
   saveModeText = "SaveAndClose";
   break;
  case 5:
   saveModeText = "Deactivate";
   break;
  case 6:
   saveModeText = "Reactivate";
   break;
  case 7:
   saveModeText = "Send";
   break;
  case 15:
   saveModeText = "Disqualify";
   break;
  case 16:
   saveModeText = "Qualify";
   break;
  case 47:
   saveModeText = "Assign";
   break;
  case 58:
   saveModeText = "SaveAsCompleted";
   break;
  case 59:
   saveModeText = "SaveAndNew";
   break;
  case 70:
   saveModeText = "AutoSave";
   break;
 }
 return saveModeText;
}

Leave a Reply

Your email address will not be published. Required fields are marked *


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>