Overriding the Default Territories Setting

When you insert a new record, the Territory field defaults to a territory called Default. This is not a true territory, but a territory placeholder. The Default entry remains in the field until the user selects a territory from the Territory field. The territories available to the user are as defined by the System Administrator.

If the user does not select a territory, the record is automatically assigned a territory according to the territory security management set up by the System Administrator and a set of system rules.

The detail of these rules are described in the System Administrators Guide.

But let's imagine that someone creates a new Company and leaves the setting to be Default. What happens is that CRM will try and add the company to the territory of the user that is assigned to the company. If the creator doesn't have insert rights over the assigned user's territory the new record will be added to the creator's territory.

So if we think about the demo system then the user Susan Maye (who is in the territory "US & Canada") can create a new company and assign it to Brian Little (territory: "US West") it will then get added to Brian's territory not Susan's. But if Brian was to try and create a company and assign it to Susan, because Brian does not have insert rights over the "US & Canada" territory for the company table the new record will get added to Brian's home territory "US West".

Now it can be the case that the System Administrator may want to create a special common territory for Companies. The System Administrator can set up security profiles so that if the records (e.g. Companies) are added to a particular territory then all users will have absolute rights to see records (Companies) in that territory. This is useful when all users of the system need to see all Companies but only the communications, opportunities and cases etc need to be kept private to the users home territory.

So if we want to make sure that when a new Company is created it gets added to that common territory by default what do we need to do?

1) The first thing to do is check that all users via their Security Profiles have rights to insert company records into the common territory. If they don't and the step 2 of the instructions are followed then you will start generating "An unexpected event has occurred" errors.

Note: When a record is attempted to be inserted into a territory by automatic code for which the user does not have insert rights then it can create a ""An unexpected event has occurred" error. This may not show up in the SQL logs but it will show up in the System Log. Things to watch out for are:

UserActionException,ErrMsg Security violation inserting into table Company. You do not have insert privileges in the XXXXXXXX territory.
An unexpected event has occurred : Exception: Security violation inserting into table Company. You do not have insert privileges in the XXXXXXX territory.

2) In the companyboxlong screen you can add the following code to the Create Script of the comp_secterr field to set the value to the common territory.

DefaultValue = -2113929208;
ReadOnly = true;

In the above example -2113929208 represents the demo territory "US West". You will need to get the value of the territory you are interested in from the table "territories".

Note: The default Person for a company created this way will get added by default to the same territory as the Company.
Anonymous
  • I think that is just the way that it works. You have to use the ReadOnly instruction to fix the value.

  • hi, thanks for graet article.

    i am trying to set Territory to some other values and it works fine if I use it with Readonly = true;

    ReadOnly = true;

    DefaultValue = -536870909;

    but if I Don't use Read only then it sets territory to Default not to -536870909

    is it possible to set territory value at Create Script not using Read Only

    Thanks

  • hi, it's me again.

    May know if I set the default Territory to my parent territory, will all the child territories under it able to see the company created by using the above method?

    Thanks and Regards,

    Shandy

  • Hi sagecrm,

    First of all, thanks for sharing. I found out that your post quite useful.

    I'm trying to modify the default setting for Territory. I able to see my parent Territory after set it. However, I get "An unexpected event has occurred" when I'm trying to Save the new Company.

    May I know how to check if all users via their Security Profiles have rights to insert company records into the common territory? Could you please guide me step by step? Currently, my employer is using Sage CRM version 6.2.

    Thanks and Regards,

    Shandy