Beiträge getagged ‘CRM 4’

Why OptimizeOrgImport is not always an optimization

12 Juli 2010

Update Rollup 8 introduced an improved organization import process which speeds up the organization import.

You have to enable the optimized import process by adding the DWORD key OptimizeOrgImport with value 1 to the registry hive of Dynamics CRM (see the detailed description http://support.microsoft.com/kb/977867)

Recently, I had a problem during an import of an organization which failed with following error

Message: Exception during import of organization (Name=’‘, Id=3e58a0cc-c277-df11-b2c1-0050569473db):
System.Data.SqlClient.SqlException: A row with a duplicate key cannot be added to the object ‘dbo.SystemUserOrganizations’-object with unique index ‘SystemUserOrganizations_CrmUserId’

The organization which I tried to import was a backup of an organization which was created in the same deployment. The import runs successful on every other deployment. With help of the Microsoft Support, we identified the cause of the issue: the OptimizeOrgImport key.

The knowledgebase article for OptimizeOrgImport contains following passage:

When you use the registry entry OptimizeOrgImport and have the value of this entry set to 1, you cannot import the same organization database more than one time.
If you want to import the same organization database more than one time, you must do one of the following things:

  • Set OptimizeOrgImport = 0 and use the normal import process.
  • Delete the organization, and then import the organization again.

This passage is a little bit misleading, as the optimized import process fails already at the first time, if the organization was created in the same deployment. In order to import a backup of an organization into the originating deployment, you have to deactivate OptimizeOrgImport.

Howto: Use pre-generated Guids for records

5 Juni 2010

A customer asked me recently if it is possible to get the id of a record in a pre-create plugin. By default, it is not possible because the record is not yet created at this point and has not got an id.

However, Dynamics CRM allows you to create your own id for a record. The primary key of a record is stored in its Key-Property. On all default entities, for example account, the id property is marked as Valid for create (see accountid). This means, the sdk allows you to pass your own id.

using System;
using Microsoft.Crm.Sdk;
 
namespace PreCreateKeyPlugin
{
    public class PreCreateKeyPlugin : IPlugin
    {
        public void Execute(IPluginExecutionContext context)
        {
            if (IsPreCreate(context))
            {
                if (context.InputParameters.Contains(ParameterName.Target))
                {
                    DynamicEntity target = context.InputParameters[ParameterName.Target] as DynamicEntity;
 
                    if (target != null)
                    {
                        Guid customId = new Guid("{d7256b93-a5b5-45f9-9f2d-a1838279c35c}");
 
                        target["accountid"] = new Key(customId);
                    }
                }
            }
        }
 
        private bool IsPreCreate(IPluginExecutionContext context)
        {
            return  context.MessageName == MessageName.Create && 
                    context.Stage == MessageProcessingStage.BeforeMainOperationOutsideTransaction;
        }
    }
}

If you register this plugin for pre-create on the account entity and create a new account, it will have the provided id.

Please keep in mind, that you are in the responsibility to assign an new GUID for every execution of this plugin, but this should be clear when working with primary keys.

Howto: Get label for an attribute with JavaScript

19 Mai 2010

If you have to retrieve the label of an attribute in a form script, you have two options. The first one, is of course not supported, but quick and easy to implement.

function GetFieldLabel(fieldname)
{
  var field = crmForm.all[fieldname+ '_c'];
 
  if (field != null){
    return field.firstChild.firstChild.nodeValue;
  }
  else {
    return '';
  }
}
 
alert(GetFieldLabel('subject'));

The other option is, to retrieve the label for the user language from the crm service. I will cover this in another article.

Howto: Detect external request with JavaScript

1 Mai 2010

If you have activated Internet Facing Deployment for your CRM system, it could be necessary to detect if a request comes from outside your network or from your internal network.

For example, if you integrate a web application with an IFrame, you have to set different addresses for internal and external access. Or, if the application is only accessible from inside your network, you can show a message that it is not available for external users.

With help of Form Scripting you can detect an external request with little effort. You can make use of the function prependOrgName(”) which adds the organization prefix to the argument, if it is necessary. That means for an external request, it returns always the argument which you have passed.

function IsExternalRequest() 
{
  var ifdTestValue = prependOrgName('');
  var isIFDCall = ifdTestValue == '';
 
  return isIFDCall;
}

Calling IsExternalRequest will return true, if the request comes from an external network range. You could also define this function globally in the form context (see also http://www.stunnware.com/crm2/topic.aspx?id=JS5)

IsExternalRequest = function() 
{
  var ifdTestValue = prependOrgName('');
  var isIFDCall = ifdTestValue == '';
 
  return isIFDCall;
}