Showing posts with label MS Dynamics Crm. Show all posts
Showing posts with label MS Dynamics Crm. Show all posts

Friday, May 25, 2012

Timeout expired on Dynamics CRM 4.0

Today I got a timeout expired error when calling a query to dynamic crm (from web service). I saw the query from trace and I when I executed it from sql server it elapsed 31 seconds. The problem was that the default timeout of sql queries in Microsoft Dynamics CRM 4.0 is 30 seconds.
This timeout can be overriden from registry by adding a DWORD value with the timeout time in seconds to the following registry key:

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSCRM\OLEDBTimeout]

Good reference of timeout specifications can be found here

Tuesday, December 28, 2010

Custom Isv.Config behavior based on User Security Roles

In Microsoft Dynamics CRM we can embed our custom solution throw sitemap, isv.config and iframe. If we want to have a custom behavior in isv.config based on User Security Roles we can inject javascript to do that.

Here is a custom button on toolbar that has custom javascript inside isv.config:

 
<ToolBar ValidForCreate="0" ValidForUpdate="0">
  <Button Icon="/_imgs/ico_16_1013.gif" ValidForCreate="0" 
ValidForUpdate="0" PassParams="1" WinMode="0" JavaScript="…………">
    <Titles>
      <Title LCID="1033" Text="Export To CSV" />
    </Titles>
      <ToolTips>
      <ToolTip LCID="1033" Text="Export To CSV" />
    </ToolTips>
  </Button>
</ToolBar>


 
Inside javascript we want a function to return all roles of a specific user by creating s SOAP message request:

//*********************
function GetCurrentUserRoles()
{
 var xml = "" +
 "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
 "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" " +
 " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">" +
 GenerateAuthenticationHeader() +
 " <soap:Body>" +
 " <RetrieveMultiple xmlns=\"http://schemas.microsoft.com/crm/2007/WebServices\">" +
 " <query xmlns:q1=\"http://schemas.microsoft.com/crm/2006/Query\" xsi:type=\"q1:QueryExpression\">" +
 " <q1:EntityName>role</q1:EntityName>" +
 " <q1:ColumnSet xsi:type=\"q1:ColumnSet\">" +
 " <q1:Attributes>" +
 " <q1:Attribute>name</q1:Attribute>" +
 " </q1:Attributes>" +
 " </q1:ColumnSet>" +
 " <q1:Distinct>false</q1:Distinct>" +
 " <q1:LinkEntities>" +
 " <q1:LinkEntity>" +
 " <q1:LinkFromAttributeName>roleid</q1:LinkFromAttributeName>" +
 " <q1:LinkFromEntityName>role</q1:LinkFromEntityName>" +
 " <q1:LinkToEntityName>systemuserroles</q1:LinkToEntityName>" +
 " <q1:LinkToAttributeName>roleid</q1:LinkToAttributeName>" +
 " <q1:JoinOperator>Inner</q1:JoinOperator>" +
 " <q1:LinkEntities>" +
 " <q1:LinkEntity>" +
 " <q1:LinkFromAttributeName>systemuserid</q1:LinkFromAttributeName>" +
 " <q1:LinkFromEntityName>systemuserroles</q1:LinkFromEntityName>" +
 " <q1:LinkToEntityName>systemuser</q1:LinkToEntityName>" +
 " <q1:LinkToAttributeName>systemuserid</q1:LinkToAttributeName>" +
 " <q1:JoinOperator>Inner</q1:JoinOperator>" +
 " <q1:LinkCriteria>" +
 " <q1:FilterOperator>And</q1:FilterOperator>" +
 " <q1:Conditions>" +
 " <q1:Condition>" +
 " <q1:AttributeName>systemuserid</q1:AttributeName>" +
 " <q1:Operator>EqualUserId</q1:Operator>" +
 " </q1:Condition>" +
 " </q1:Conditions>" +
 " </q1:LinkCriteria>" +
 " </q1:LinkEntity>" +
 " </q1:LinkEntities>" +
 " </q1:LinkEntity>" +
 " </q1:LinkEntities>" +
 " </query>" +
 " </RetrieveMultiple>" +
 " </soap:Body>" +
 "</soap:Envelope>" +
 "";
 
 var xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
 xmlHttpRequest.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
 xmlHttpRequest.setRequestHeader("SOAPAction"," http://schemas.microsoft.com/crm/2007/WebServices/RetrieveMultiple");
 xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
 xmlHttpRequest.setRequestHeader("Content-Length", xml.length);
 xmlHttpRequest.send(xml);
 
 var resultXml = xmlHttpRequest.responseXML;
 return(resultXml);
}
//*********************

Then we need a function to check if specified user has specified role:

//*********************
function UserHasRole(roleName) {
    //get Current User Roles, oXml is an object
    var oXml = GetCurrentUserRoles();
    if (oXml != null) {
        //select the node text
        var roles = oXml.selectNodes("//BusinessEntity/q1:name");
        if (roles != null) {
            for (i = 0; i < roles.length; i++) {
                if (roles[i].text == roleName) {
                    //return true if user has this role
                    return true;
                }
            }
        }
    }
    //otherwise return false
    return false;
}
//*********************

Finally we have the actual code for button. Our intention is to check if a user has a specific security role (by name) and if he has it, to restrict him from making executing the action of button.
 
if(!UserHasRole("No CSV Export"))
{
  // OK pass and go to custom solution for making the export
  window.open('/ISV/CRMISVCustoms/ExportToCSV.aspx?orgname=' + ORG_UNIQUE_NAME,'ExportCSV','width=500,height=200,resizable=yes');
}
else
{
   // Not authorized
   alert('You are not authorized to Export in csv');
}


Monday, December 13, 2010

Microsoft Dynamics CRM limits export to 10000 rows to Excel

Our customer is making lists of contacts to send then in third parties for process. The number of contacts in those list can be larger than 50000. When we made an export to excel we saw that only 10000 contacts where exported. It turned out that there was a limitation in the organization database for exporting only 10000 rows from excel. The solution was easy. We changed the limit value from sql server (table OrganizationBase field MaxRecordsForExportToExcel). The query was:

update OrganizationBase set
      MaxRecordsForExportToExcel = 65500

After the query we made a restart of iis and everything worked.

Thursday, December 2, 2010

The E-mail Router service could not run the service main background thread

Well I found in a Microsoft Dynamics CRM 4.0 rollup 10 with email router (on-premise) deployment that the email router service was stopped. I tryed to start the service and I couldn' t. I looked at event viewer and I found this log:

#16192 - The E-mail Router service could not run the service main background thread. The E-mail Router service cannot continue and will now shut down. System.Configuration.ConfigurationErrorsException: The E-mail router service cannot access system state file Microsoft.Crm.Tools.EmailAgent.SystemState.xml. The file may be missing or may not be accessible. The E-mail Router service cannot continue and will now shut down. ---> System.Xml.XmlException: Root element is missing.
   at System.Xml.XmlTextReaderImpl.Throw(Exception e)
   at System.Xml.XmlTextReaderImpl.ParseDocumentContent()
   at System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader, Boolean preserveWhitespace)
   at System.Xml.XmlDocument.Load(XmlReader reader)
   at System.Xml.XmlDocument.Load(String filename)
   at Microsoft.Crm.Tools.Email.Providers.ConfigFileReader..ctor(String filePath, ServiceLogger serviceLogger)
   at Microsoft.Crm.Tools.Email.Providers.SystemState.Initialize(ServiceLogger serviceLogger)
   at Microsoft.Crm.Tools.Email.Agent.ServiceCore.InitializeSystemConfiguration()
   --- End of inner exception stack trace ---
   at Microsoft.Crm.Tools.Email.Agent.ServiceCore.InitializeSystemConfiguration()
   at Microsoft.Crm.Tools.Email.Agent.ServiceCore.ExecuteService()

After some search I found here that file Microsoft.Crm.Tools.EmailAgent.SystemState.xml was corrupted. I deleted the file and started the email router service.

Thursday, April 15, 2010

Crm Integration Using SSIS

A common situation in Microsoft Dynamics CRM is to integrate data from a foreign system. In order to do that we must read data from the external source and import then using custom rules inside CRM using the webservice. An easy approach is to use SQL integration services. The tricky part of this approach is how to consume the CRM web service inside Ingration Services. The article below shows an easy way to do that.

http://blogs.msdn.com/crm/archive/2008/05/07/integrating-crm-using-sql-integration-services-ssis.aspx

Tuesday, April 6, 2010

Problem after deleting Active Directory User Account

I found my self in a strange situation after disabling a user from Microsoft Dynamics CRM 4.0 and the deleting the user from Active Directory. I couldn’t enable again the user because there was no Active Directory User associated with it. I tried many solutions to bypass this problem but they did not worked for me. The only solution that worked was to remove the company from the deployment (I made a backup first, just in case) and then I import the same company. When importing a company Microsoft Dynamics CRM 4.0 make new associations of crm users with active directory users, so I matched the disabled user with a new account of active directory.