Code example: CRMListBlock object

This example creates a case list from the company context, where the status and stage columns are removed if the user isn't on the Sales team. A FoundIn column is added if the user is on the Operations team.

Copy
<!-- #include file ="sagecrm.js"-->
<%

// Get the current Company ID.
ThisCompanyId = CRM.GetContextInfo('Company','Comp_CompanyId');

// Get a reference to the CaseListBlock.
CaseListBlock = CRM.GetBlock('CaseListBlock');

// Build the SQL WHERE clause.
SearchSql = 'Case_PrimaryCompanyId='+ThisCompanyId + " and Case_Status='In Progress' "

// Check the user's team ID.
UserChannel = CRM.GetContextInfo('User','User_PrimaryChannelId');

// Remove fields if the user's team is not Sales. 
// 1 in the code below is the Channel ID of the Sales team.
if (UserChannel != 1) 
    {
        CaseListBlock.DeleteGridCol('Case_Status');
        CaseListBlock.DeleteGridCol('Case_Stage');
    }

// Add field for Development team.
// 5 in the code below is the Channel ID of the Operations team.
if (UserChannel == 5) 
    {
        FoundIn = CaseListBlock.AddGridCol('Case_FoundVer');

        // Enable sorting by the Found In column.
        FoundIn.AllowOrderBy = true;
    }

// Execute the block, pass in the SQL clause.
CRM.AddContent(CaseListBlock.Execute(SearchSql));
Response.Write(CRM.GetPage());

%>