Sunday, August 5, 2012

MSCRM 2011 - Plugin View

In this post I will show steps by steps how to implement plugin on Retrieve Multiple Message using the plug-in registration tool for Microsoft Dynamics CRM 2011

1. Step Create a new plugin

2. Add the following  code snippets.  Fieldname is the field that you want to check (example name of account).

// Comment
protected void ExecuteViewController(LocalPluginContext localContext)
        {
            if (localContext == null)
            {
                throw new ArgumentNullException("localContext");
            }
            IPluginExecutionContext context = (IPluginExecutionContext)localContext.PluginExecutionContext;
            IOrganizationService service = localContext.OrganizationService;
            QueryExpression qe = (QueryExpression)context.InputParameters["Query"];
            if (qe.Criteria.Conditions != null)
            {
                ConditionExpression queryCondition = new ConditionExpression("fieldname", ConditionOperator.Equal, "value");
                context.InputParameters["Query"] = qe;
            }
        }


3. Add plugin step (example: Account on entity)


4. If you want to add other steps you must repeat third step and you must register the associate event as below.

// Comment
public FilteredViewController()
            : base(typeof(FilteredViewController))
        {
            base.RegisteredEvents.Add(new Tuple>(20, "RetrieveMultiple", "appointment", new Action(ExecuteFilteredViewController)));
            base.RegisteredEvents.Add(new Tuple>(20, "RetrieveMultiple", "account", new Action(ExecuteFilteredViewController)));
            base.RegisteredEvents.Add(new Tuple>(20, "RetrieveMultiple", "lead", new Action(ExecuteFilteredViewController)));
            // Note : you can register for more events here if this plugin is not specific to an individual entity and message combination.
            // You may also need to update your RegisterFile.crmregister plug-in registration file to reflect any change.
        }


Notes:
Previous code snippets (ExecuteViewController) can be used for each entities that contains the target field (fieldname).


Thanks,
Nicola Grillo

Sunday, June 17, 2012

MS CRM 2011 - Javascript function to detect Offline/Online mode

The following example shows how to enable or disable a MS Crm Tab when an user tries to go in offline mode or in online mode. In this case i try to disable the tab that contains an Iframe with a Custom Service Calendar.


// Comment
HeadServiceCalendarInOfflineMode: Function()
{
//Check if mscrm is in online or offline mode

if(!isOnline)
{
try
{
Xrm.Page.ui.tabs.get("service_calendar_Tab").setVisible(false);
}catch(err){}
}

}


Nicola Grillo