Saturday, July 21, 2012

Conditionally Hiding OOB Ribbon Button in CRM 2011

Hi All, To hide the OOB Ribbon button permanently you can use my earlier post. But sometimes we needs to hide OOB Ribbon button conditionally in CRM 2011.  Here I am going to hide OOB "Assign" button conditionally based on Optionset Value.

       On the Account form, if the "Category"  optionset value is "Preferred Customer" then display the "Assign" button otherwise hide the "Assign" button.



1. Export the solution and open Customization.XML file in edit mode. Find the <RibbonDiffXml> at the Account form level.





2. Now open Accountribbon.xml file from the SDK and find the Assign button details at form Level

      
 Now copy the Assign button element from here and add this to custom Actions in the <RibbonDiffXML> which we are customizing.
 we also needs to copy the CommandDefinition of the OOB Assign button to provide OOB assign functionality. otherwise OOB Asign button functionality might not work.

3. Now edit the Account <RibbonDiffXML> in the following way

 <RibbonDiffXml>
        <CustomActions>
          <!-- Location will be ID of the Button-->
          <CustomAction Location="Mscrm.Form.account.Assign" Id="Sample.Form.account.HideAssign">
            <CommandUIDefinition>
              <!-- copy the OOB Asign button CommandUI Definition-->
              <Button Id="Mscrm.Form.account.Assign" ToolTipTitle="$Resources:Ribbon.HomepageGrid.MainTab.Actions.Assign" ToolTipDescription="$Resources(EntityPluralDisplayName):Ribbon.Tooltip.Assign" Command="Mscrm.AssignPrimaryRecord" Sequence="33" LabelText="$Resources:Ribbon.HomepageGrid.MainTab.Actions.Assign" Alt="$Resources:Ribbon.HomepageGrid.MainTab.Actions.Assign" Image16by16="/_imgs/ribbon/Assign_16.png" Image32by32="/_imgs/ribbon/Assign_32.png" TemplateAlias="o1" />
            </CommandUIDefinition>
          </CustomAction>
        </CustomActions>
        <Templates>
          <RibbonTemplates Id="Mscrm.Templates"></RibbonTemplates>
        </Templates>
        <CommandDefinitions>
          <!-- copy the OOB Asign button Command Definition-->
          <CommandDefinition Id="Mscrm.AssignPrimaryRecord">
            <EnableRules>
              <EnableRule Id="Mscrm.FormStateNotNew" />
              <EnableRule Id="Mscrm.AssignPrimaryPermission" />
              <EnableRule Id="Mscrm.NotOffline" />
            </EnableRules>
            <DisplayRules>
              <DisplayRule Id="Mscrm.AssignPrimaryPermission" />
              <DisplayRule Id="Mscrm.NotClosedActivity" />
              <!-- Add new display Rule for conditionally hiding-->
              <DisplayRule Id="Sample.Form.account.HideAssign.DisplayRule"/>
            </DisplayRules>
            <Actions>
              <JavaScriptFunction FunctionName="assignObject" Library="/_static/_forms/form.js">
                <CrmParameter Value="PrimaryEntityTypeCode" />
              </JavaScriptFunction>
            </Actions>
          </CommandDefinition>
        </CommandDefinitions>
        <RuleDefinitions>
          <TabDisplayRules />
          <DisplayRules>
            <!--Define the conditional Hiding Display Rule-->
            <DisplayRule Id="Sample.Form.account.HideAssign.DisplayRule">              
              <ValueRule Field="accountcategorycode" Value="1"/>
              <!--Field will be CRM field schema Name, Value will be optionset Value-->
            </DisplayRule>
          </DisplayRules>
          <EnableRules />
        </RuleDefinitions>
        <LocLabels />
      </RibbonDiffXml>
 

4. Now import the customization file.

Hope it helps!!!

Friday, July 13, 2012

Plugin on Retrieve Multiple Message in CRM 2011

Hi All, Now will see how to implement plugin on Retrieve Multiple Message. While Retrieving Data from an entity, I needs to check the query passed by the user and based on the filters, adding conditional filters and returning filtered information to the user.


        public void Execute(IServiceProvider serviceProvider)
        {
            // Extract the tracing service.
            ITracingService tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
            if (tracingService == null)
                throw new InvalidPluginExecutionException("Failed to retrieve the tracing service.");
            try
            {
                tracingService.Trace("Posting the execution context.");
                if (tracingService == null)
                    throw new InvalidPluginExecutionException("Failed to retrieve the service bus service.");
                
                IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
                string city = string.Empty;

               if (context.MessageName == "RetrieveMultiple") 
                {
                    if (context.Depth <= 1)
                    {
                        IOrganizationServiceFactory factory =
                            (IOrganizationServiceFactory)
                            serviceProvider.GetService(typeof (IOrganizationServiceFactory));
                        IOrganizationService service = factory.CreateOrganizationService(null);


                        if (context.InputParameters.Contains("Query"))
                        {
                               // Get the query
                            QueryExpression query = (QueryExpression)context.InputParameters["Query"];
                          // get the conditions passed by the user
                            ConditionExpression[] filters = query.Criteria.Conditions.ToArray();

                            foreach (var filter in filters)
                            {
                                if (filter.AttributeName == "new_city")
                                    city = filter.Values[0].ToString();
                                //check if the query has city filter
                                if (!string.IsNullOrEmpty(city) && city == "MyCity")
                                {

                                        // write your logic,  adding additional filters conditionally or performing other tasks etc..
                                                                      
                                }
                            }
                           
                           
                        }
                       
                    }

                }
            }
            catch (FaultException<OrganizationServiceFault> e)
            {
                tracingService.Trace("Exception occured in the Plugin:" + e.ToString());
                // Handle the exception.
                throw;
            }
            catch (Exception ex)
            {
                tracingService.Trace("Exception: {0}", ex.ToString());
                throw;
            }
        }

Hope it helps!!!

Tuesday, June 19, 2012

Javascript debugger not working on Ribbon Button click

Recently I tried debugging java script code which is called on ribbon button click. But i am not able to debugger that code. I am able to debug javascript on form level. But not on Ribbon button level. Looks strange!!

      I tried solution provided in this forum post , but its partially resolved debugging issue.

After digging deep, I tried upgrading IE version from IE8 - IE9. Finally debugging issue on ribbon button click has been resolved.

Hope it will be helpful!!!

Friday, April 27, 2012

Tab order Issue with CRM 2011 Managed Solution

Recently I was deploying managed solution into a new environment. Deployment done successfully without errors. But I notice an issue with managed solution deployment in CRM2011.

      With Managed solution import, All the OOB entities having wrong tab order. Then i came to know Managed solutions merge changes to the existing customizations file instead of replacing.
http://msdn.microsoft.com/en-us/library/gg309329.aspx
Microsoft has to resolve this issue.

Workaround: Manually editing the customizations.xml of managed solution & reordering the tab sequence. Then importing managed solution to the host system. Now it will get the correct tab order.

It's not a good idea, but hope it helps!!!

Saturday, March 17, 2012

Completed Customization's Certification in CRM 2011..

Today I completed Customization's Certification in CRM 2011 and became  Microsoft Certified Technology Specialist  in Microsoft Dynamics™ CRM 2011...

             Just wanted to share with all my buddies.. keep exploring things in CRM 2011..

Keep smiling.. :)