Saturday, February 11, 2012

MSCRM 2011 javascript validate lead qulify javascript

Sometimes validation of fields is needed before qualifying a lead.
Setting the fields to be required isn't good enough, because there is no need to require the fields for every save.
It can be done using javascript on form save event.

Check if the save mode equals 16 (lead qualify) by using

ExecutionObj.getEventArgs().getSaveMode()

Use prevent default to prevent the page from saving and qualifying.
ExecutionObj.getEventArgs().preventDefault()


Microsoft link about preventDefault
http://msdn.microsoft.com/en-us/library/gg509060.aspx#BKMK_preventDefault

Microsoft link about getsavemode
http://msdn.microsoft.com/en-us/library/gg509060.aspx#BKMK_GetSaveMode

Good wiki that extends more about getsavemode and preventDefault
http://social.technet.microsoft.com/wiki/contents/articles/4122.aspx


MSCRM 2011 get optionset value (int) by its label (string) c#


This is here that I'll stop forgetting it and look for it everywhere.


internal int GetOptionsSetValueByText(Xrm.XrmServiceContext xrmService, string entityName, string attributeName, string optionSetTextValue)
    {
        RetrieveAttributeRequest retrieveAttributeRequest = new RetrieveAttributeRequest
        {
            EntityLogicalName = entityName,
            LogicalName = attributeName,
            RetrieveAsIfPublished = true
        };
        RetrieveAttributeResponse retrieveAttributeResponse = (RetrieveAttributeResponse)xrmService.Execut(retrieveAttributeRequest);
        if (retrieveAttributeResponse != null)
        {
            PicklistAttributeMetadata optionsetAttributeMetadata = retrieveAttributeResponse.AttributeMetadata as PicklistAttributeMetadata;
            if (optionsetAttributeMetadata != null)
            {
                OptionMetadata[] optionsetList = optionsetAttributeMetadata.OptionSet.Options.ToArray();
                foreach (OptionMetadata optionsetMetaData in optionsetList)
                {
                    if (optionsetMetaData.Label.UserLocalizedLabel.Label == optionSetTextValue)
                    {
                        return optionsetMetaData.Value.Value;
                    }
                }
            }
        }
        return -1;
    }

Thursday, February 9, 2012

MSCRM 2011 early binding plugin using developer toolkit

In the past I've created a walkthough blog about how to create plugin running early binding in online environment.

This is the another option (easier one) for creating it using CRM developer toolkit which comes with the Dynamics CRM 2011 SDK.

General knowledge about CRM developr toolkit

Other good step by step blog for building plugin using developer toolkit

Creating plugin using developer toolkit:

1) Install CRM developer toolkit
2) Create new developer Project
3) Create new plugin project. The great thing about it, it comes with all the relevant references in it.
4) Generate the wrapper (CrmSvcUtil)
5) Choose the entity you wish to add plugin for
6) Choose plugin configuration



And that's it, Start writing plugins..