Generic dostinex ukLexapro generic pill description Disable / enable fields, sections, tabs and the whole form in CRM 2011

When working with CRM, you often want to enable (set to read/write) or disable (set to read / only) selected fields, sections, tabs and the whole form depending on your business logic. This is can be derived from studying the SDK and creating som code, but here are my easy-to-use support functions to complement the base functions.

1) Enable / Disable a field

Xrm.Page.getControl("fieldname").setDisabled(false);  // true = R/W, false = R/O

2) Enable / Disable a Section

function sectiondisable (sectionname, disablestatus)
    var ctrlName = Xrm.Page.ui.controls.get();
    for(var i in ctrlName) {
         var ctrl = ctrlName[i];
         var ctrlSection = ctrl.getParent().getName();
         if (ctrlSection == sectionname) {
}  // sectiondisable

3) Enable / Disable a Tab

function tabdisable (tabname, disablestatus)
 var tab = Xrm.Page.ui.tabs.get(tabname);
 if (tab == null) alert("Error: The tab: " + tabname + " is not on the form");
 else {
     var tabsections =  tab.sections.get();
     for (var i in tabsections) {
         var secname = tabsections[i].getName();
         sectiondisable(secname, disablestatus);
}   // tabdisable

4) Enable / Disable a Form

function formdisable(disablestatus)
    var allAttributes =;
    for (var i in allAttributes) {
           var myattribute =[i].getName());
           var myname = myattribute.getName();          
} // formdisable
Posted in CRM 2011, Javascript | 2 Comments

Remember old / previous values in CRM form

A typical need is to remember a previous value on a CRM form, so that if a user makes an error, we can set the field back to its original value. The problem is that when we run an on change event function on a field we of course get the new value. We want to know what the original value was.

Let’s say we have a CRM field called global_importantfield. We could make an extra field called global_oldvalueofimportantfield and put this on a hidden part of the form. Then by Javascripting you could set the value of global_oldvalueofimportantfield to the global_importantfield upon load. This is not an ideal solution since you then create uneccessary database fields. Also, if you have many fields where such initial / previous values are needed, you will need to create a lot of fields.

A smarter approach is to create a function that we on load will populate with our initial values. Then we can call upon this dummy function with the right “variable” from other Javascript functions.  We can also change and modify the content of these variables from other functions. This is how it is done:

You have a jscript web resource for the entity. In this you have your functions and code.

1) Code that is run onload:

if ( Xrm.Page.getAttribute('global_importantfield').getValue() != null  )  
   InitValues.IMPFIELD = Xrm.Page.getAttribute('global_importantfield').getValue();
 else InitValues.IMPFIELD = "";
if ( Xrm.Page.getAttribute('global_anotherfield').getValue() != null  )  
   InitValues.ANOTHERFIELD = Xrm.Page.getAttribute('global_anotherfield').getValue();
 else InitValues.ANOTHERFIELD = "";
// End of onload code

2) Then you must have a dummy function in your jscript web resource:

function InitValues() { }

3) Usage in other functions

To use and manipulate these values - your can for example have the following code in the function that is run on-event for the  global_importantfield:

var newcontent = Xrm.Page.getAttribute('global_importantfield').getValue();
alert("The new value is:" + newcontent );
alert("And here is the previous value" + InitValues.IMPFIELD);</pre>

If let’s say that the user confirms the choice, you might want to set the IMPFIELD to the new choice right away since it else will only be updated on a new save and load of the form:

InitValues.IMPFIELD = newcontent; 
Posted in CRM 2011, Javascript | Leave a comment

Choice of tracking token may mark your emails as spam

I had an interesting experience with sending marketing mails from CRM. I usually have a test list where I send new outbound mails to check how they look in different e-mail clients etc. I discovered that my own e-mails from CRM were caught by our company spam filter and marked as spam. After some testing I discovered that the culprit was the use of the “:” in the tracking token for our CRM e-mail setup. Our tracking token was of the form xxxxx ErgoGroup:000324. You can quite easily change the tracking token in CRM 4 by going to System Settings – E-mail.

You cannot have a prefix just with ErgoGroup + a space to get a token such as “ErgoGroup 00324″, it will always end up as “ErgoGroup00324″, and this kind of text in the message header might also mark the email as spam. I therefore changed the prefix to “ErgoGroup n”, so that  the tracking token that gets created look like this: “ErgoGroup n00234″. This looks OK on e-mails to our customers, and most important: our messages do not end up marked as spam.

Posted in CRM 4, e-mail, Marketing | Leave a comment

Sharing our CRM travels…

This site is about sharing our experiences working with Microsoft Dynamics CRM. Even if we all work at EDB ErgoGroup, this is a personal project – and all opinions and statements are our own, and not in any way condoned or sanctioned by the company.

We hope the articles here will be of use for you regardless if you are a power user, a system customizer or a CRM developer.

Posted in Uncategorized | Leave a comment