Current Context and User data used to control a Tab

1 minute read time.
In a previous article "Tab SQL Clause" I discussed how it is possible to separate SQL clauses with a ";" character. So in a Company Tab group the Opportunity tab can be guarded by a SQL clause statement like:

comp_type='customer';comp_status='active'

I have also described in the article "The SQL Tab Clause and the User Admin screens" that when you enter a SQL Tab condition associated with an option in a Tabgroup you can either work with the current entity in context or the current user in context.

Either the SQL clause

comp_type = 'customer'

or the clause

user_primarychannelid = 1

can be used. But not together. If there is a business requirement to only show the opportunities tab in the company context if the user is in the Sales team and the company is of type 'Customer'. We may be tempted to try and use

user_primarychannelid = 1 and comp_type = 'customer'

This creates an SQL Error from the passed SQL.

select * from vusers where user_userid=4 and (user_primarychannelid = 1 and comp_type = 'customer')

Instead we can use two seperate predicates.

user_primarychannelid = 1; comp_type = 'customer'

This results in the SQL.

select * from vusers where user_userid=4 and (user_primarychannelid = 1)

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
and will control the display of the tab so it only shows when the user is in the Sales team and the company is of type 'Customer'.