Summary:

In CRM, it is impossible to create a custom view longer than 3900 characters. A Maxlength property exists on the View Script field which prevents longer views from being entered.

Cause:

The restriction is imposed by a MaxLength property on the view textarea. The CuVi_ViewScript field on Custom_Views is an nvarchar(max) field, and the maximum query length for a view is much greater than 3900 characters. The restriction likely comes from the need to support versions of Microsoft SQL Server predating the introduction of nvarchar(max).

This issue has been raised to the development team, with a view to clarifying the restriciton.

Workaround:

One possible approach is to try breaking your view up into multiple sub-views. Here’s an example long view:

create view vLongView as
select Comp_CompanyId, Comp_Name, Comp_Status, Comp_CreatedBy,
       Comp_CreatedDate, Comp_UpdatedBy, Comp_UpdatedDate,
Comp_PrimaryPersonId, Comp_Deleted,
Pers_PersonId, Pers_FirstName,
       Pers_LastName, Pers_Status, Pers_CreatedBy, Pers_CreatedDate,
       Pers_UpdatedBy, Pers_UpdatedDate, Pers_Deleted
from Company
left join Person on Comp_PrimaryPersonId = Pers_PersonId
where Comp_Deleted is null and Pers_Deleted is null

Obviously, this is much shorter than 4000 characters (it’s fewer than 500), but it will do for making our point. We can split this into 2 sub-views, with a much shorter custom view tying them together:

create view vCompanySubView as
select Comp_CompanyId, Comp_Name, Comp_Status, Comp_CreatedBy,
       Comp_CreatedDate, Comp_UpdatedBy, Comp_UpdatedDate,
       Comp_PrimaryPersonId, Comp_Deleted
from Company
where Comp_Deleted is null

create view vPersonSubView as
select Pers_PersonId, Pers_FirstName, Pers_LastName,
       Pers_Status, Pers_CreatedBy, Pers_CreatedDate,
       Pers_UpdatedBy, Pers_UpdatedDate, Pers_Deleted
from Person
where Pers_Deleted is null

create view vShortView as
select comp.*, pers.*
from vCompanySubView comp left join vPersonSubView pers
       on comp.Comp_PrimaryPersonId = pers.Pers_PersonId

 

If long views are to be edited on a frequent basis, then a custom JavaScript function can be added to \CRM\WWWRoot\js\custom\:

crm.ready(function () {
    $('#CuVi_ViewScript').removeAttr('maxlength');
});

This attribute removes the MaxLength attribute associated with the text field.