Wednesday, November 23, 2011

Reset App Pool in Command Line

One of major issue happens when you customize CRM entities is, even you publish the solution, SOMETIMES your changes are not getting applied and hence you need to do a IIS Reset. This is becomes an issue,

1. when the client is also accessing the system
2. QA team performing testing in the same CRM Instance
3. Your team members may be using the system or in a debugging their code.

So instead of doing a IIS Reset, you can do a Application Pool reset. But normally that need to open the Internet Information Service (IIS InetMgr.exe) and need to navigate to App pools and you have to manyually reset all the relevent application pools.
Instead of that you may create a bat file, and call once.

@echo off
echo.
echo recycling 'CRMAppPool' Application Pool
%windir%\System32\inetsrv\appcmd recycle apppool /apppool.name:CRMAppPool
echo.

Thursday, November 17, 2011

Hide Section in CRM 2011

Do you want to hide a section in CRM 2011?

Steps

1. Open the customization form
2. Double click the section and copy the section Label. Let's say it's name is 'General'
3. Copy the below java script function
function HideSection(sectionLabel)
{
   try
   {
       var tabs = Xrm.Page.ui.tabs;
       for (var i = 0; i < tabs.getLength(); i++)
       {
           var tab = tabs.get(i);
           var sections = tab.sections;
           for (var j = 0; j < sections.getLength(); j++)
           {
               var section = sections.get(j);
               if (section.getLabel() == sectionLabel)
               {
                   section.setVisible(false);
                   break;
               }
           }
       }
   }
   catch (err)
   {
   }
}

4. Call the function in CRM Form Load event
HideSection('General');

Wednesday, November 2, 2011

Cancel/Inactivate a record when it is already in the same status


You many need to cancel Order, Invoice or any other record using workflow.
Before cancelling the workflow, you must check whether the record is already in cancel status.
If the record is already in cancel status, when you are trying to cancel it again, you will experience below error.


Workflow paused due to error: Unhandled Exception:
System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]: 
The entity cannot be closed because it is not in the correct state.Detail:
-2147220941 The entity cannot be closed because it is not in the correct state. 2011-11-02T06:09:20.2231504Z
-2147220941 The entity cannot be closed because it is not in the correct state. 2011-11-02T06:09:20.2231504Z
at Microsoft.Crm.Extensibility.OrganizationSdkServiceInternal.Execute(OrganizationRequest request, CorrelationToken correlationToken, CallerOriginToken callerOriginToken, WebServiceType serviceType) at Microsoft.Crm.Extensibility.InprocessServiceProxy.ExecuteCore(OrganizationRequest request) at Microsoft.Crm.Workflow.Services.SetStateActivityService.<>c__DisplayClass1.b__0(IOrganizationService sdkService) at Microsoft.Crm.Workflow.Services.ActivityServiceBase.ExecuteInTransactedContext(ActivityDelegate activityDelegate) at Microsoft.Crm.Workflow.Services.SetStateActivityService.SetStateInternal(String entityName, Guid entityId, Int32 state, Int32 status) at Microsoft.Crm.Workflow.Services.SetStateActivityService.ExecuteInternal(ActivityContext executionContext, SetState setState) at Microsoft.Crm.Workflow.Services.SetStateActivityService.Execute(ActivityContext executionContext, SetState setState) at System.Activities.CodeActivity.InternalExecute(ActivityInstance instance, ActivityExecutor executor, BookmarkManager bookmarkManager) at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor, BookmarkManager bookmarkManager, Location resultLocation)

Tuesday, November 1, 2011

Workflow Scope

One of big mistakes we do when we are implementing CRM workflows are we do not set the Workflow scope. By default CRM sets the workflow scope to User Level

So the workflow is executing only when the workflow assign user triggers the workflow. To fix the problem, you have to set the scope to 'Organization' level, so the workflow will fire when any user execute a task that triggers the workflow.