Using Create Script in GridColumns

1 minute read time.

In the image below we can see the Company Name is displayed in an opportunity list that is in the context of the company and so that column is redundant and does not need to be shown.

The list is created by the opportunitylist system action which is used in a number of contexts

  • My CRM
  • Person
  • Company
  • etc

The system action uses a block of the same name 'opportunitylist'.

The columns that are added to List blocks may have create scripts associated with them in a similar manny to the fields in a EntryGroup (screen) block. Of course, lists are not going to be in Edit mode. Their job is to display data. but we can use the Create Script to change the properties of the column.

We can use a test for context and add this code into the screen

if (CRM.GetContextInfo("company","comp_companyid"))
{
Visible = false;
}

This will cause the column to be suppressed in when the company is in context.

GridColumn properties

Columns within a List block as correctly known as GridColumn blocks. There are a number of properties that can be set in the create script. These various properties are discussed in the documentation.

In code such as ASP pages and in the .NET API create scripts can be programmatically added to the columns. e.g.

var myGridColBlock = myBlock.GetGridCol("comp_name");
myGridColBlock.CreateScript = "if (CRM.GetContextInfo('company','comp_companyid')){Visible = false;}";