Wednesday, May 26, 2010

SharedVariables

I came across a good MSDN article about a plugin feature that I personally think most people overlook.  That feature is SharedVariables.  It is a way to pass data from the pre event to the post event in your plugin so that your post event plugin can use the data as needed.  It is probably very rare that you would ever need to use this functionality (I've only used it once out of the dozens upon dozens of plugins I've developed) but it is good to know it exists.

http://msdn.microsoft.com/en-us/library/cc151094.aspx 

Tuesday, May 11, 2010

ActivityParty Property Con't

Last month I made a post about grabbing an ActivityParty property from a DynamicEntity and recently someone on the CRM forums made a post asking how to add an ActivityParty property to a DynamicEntity.  This can be very confusing and not straightforward at all so I'm going to post the snippet that I answered with in hopes to help some people out.

            DynamicEntity email = new DynamicEntity("email");
            // setup email attributes

            DynamicEntity contactParty = new DynamicEntity("activityparty");
            contactParty.Properties.Add(new LookupProperty("partyid", new Lookup("contact", new Guid("Contact ID"))));

            email.Properties.Add(new DynamicEntityArrayProperty("to", new DynamicEntity[] { contactParty}));

Note:  Shan McArthur replied to the post on the forum saying that this becomes easier with the new XRM dlls from the latest SDK.  Hopefully I can play around with these new dlls soon and be able to post some updated snippets.

Sunday, May 9, 2010

Thursday, May 6, 2010

Changing a Form Field Label

A question was posted in the CRM Forums on how to change a form field's label using javascript onload.  One thing people might not consider is that if you just change the innerText of the field label and the field is required then you will override the asterisk image that is next to the label.

To change the field label correctly, we will need to find the label element and change it's text to our new label rather than overriding the innerText.  Below is an image of the DOM of a field label in Dev Toolbar where I'm highlighting the text that we are going to find and change.



Here's the script to do so:

function changeFieldLabel(fieldName, newLabel)
{
     var field = crmForm.all[fieldName + "_c"];
     if (field != null)
          crmForm.all[fieldName + "_c"].firstChild.firstChild.nodeValue = newLabel;
}

Which you can use like so:
changeFieldLabel("name", "New Name");