Schlagwort-Archive: HowTo

Howto: extend the maximum value for duration attributes

If you have ever tried to enter a duration of more than 10 days for a service activity you would have seen that the system won’t accept this value.

The duration of the appointment is invalid

If you need to change the maximum value you are able to do this directly in the database (which is officially supported – quote of a support ticket below).

  • There is no way to modify the limit for service duration via UI. We will read this value from a SQL table and there we can change the default setting.

    Database: [Organization]_MSCRM

    Table: OrganizationBase

    Field: MaxAppointmentDurationDays

    Default value: 10

  • If you overwrite this value with the needed one (for example 20) and after that perform an IISReset, the known error message (“The duration of the appointment is invalid”) will no longer occur.

    This change is the recommended solution from Microsoft CRM Support and will be supported.

  • Background: This field does come originally from CRM 3.0, where customer already provided feedback that the maximum duration of 10 days does not meet their need. The solution for CRM 3.0 was a solution implementation via registry key: Navigate to the following registry hive: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSCRM. Create a registry key of type DWORD and name it “SchedulingEngine.MaxAppointmentDurationDays”. Provide a reasonable digit greater than 10 representing the number of days the service activity would be kept open and insure that the value is set to Decimal and not Hexadecimal. Now you can schedule an appointment with a duration value of more than 10 days.
  • For CRM 4.0 you will need a manual change of the according OrganisationBase entry. Exception: If you upgrade your CRM installation from CRM 3.0 to CRM4.0, the value will be automatically carried over

Another possibility to adjust this setting is to change the organization.maxappointmentdurationdays Property via the sdk.

Howto: Use pre-generated Guids for records

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

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

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;
}