Tab SQL clause

2 minute read time.
This controls the display of the tab via SQL. We can decide whether a tab should display based on the information of the entity that is in context. If we are looking at a person screen the person entity is in context. If we are looking at the company screen then the company is in context.

For example in the company entity context we may want to only have the opportunities tab displayed if the company is of type 'customer'. If we put in the SQL field, the clause

comp_type ='customer'

This works and hides the opportunities tab unless the company is a customer and in the logs we would see the actual SQL rendered as

select * from vcompany where ((comp_secterr is null OR (comp_ChannelId=1) OR (Comp_PrimaryUserId=4) OR (comp_CreatedBy=4) OR (comp_secterr>=-2147483639 AND comp_secterr=-1610612729 AND comp_secterr


The SQL that can be placed in the SQL clause is highly sensitive because of the way that Sage CRM will take our simple predicate and add it to the actual SQL that is run. In the above SQL sample we can see that for the user who was attempting to access the record the security territory and profile clauses are also included.


It is possible to separate SQL clauses with a ";" character. So in a Company Tab group on the Opportunity tab a SQL clause statement like:

comp_type='customer';comp_status='active'

would be valid. This technique is used in some integrations with Sage business management software.

The above multiple clause example would result in two checks being made.

select * from vcompany where ((comp_secterr is null OR (comp_ChannelId=1) OR (Comp_PrimaryUserId=4) OR (comp_CreatedBy=4) OR (comp_secterr>=-2147483639 AND comp_secterr=-1610612729 AND comp_secterr=-2147483639 AND comp_secterr=-1610612729 AND comp_secterr

In order for the Opportunity Tab to display, both SQL clauses must return data. If either condition is not satisfied then the tab is not displayed.

In this case the same effect can be achieved by using the single clause

comp_type='customer' and comp_status='active'



The SQL clause can be made more complex with each of the following a valid form:

  • comp_type ='customer' or comp_type = 'prospect'
  • comp_type in ('customer', 'prospect')
  • comp_type = 'customer' and comp_status = 'active'
  • comp_type = 'customer' and comp_source is not null
  • comp_type = 'customer' and exists (select * from opportunity where oppo_primarycompanyid = comp_companyid)