Collecting Information from Checkboxes in TableLevel Scripts

2 minute read time.

A customer had a requirement to add a series of check boxes to the Lead screen. The check boxes would allow the user to quickly classify and collect the different interests of a prospect as it the new Lead was entered into the system. Once the lead was saved a summary of the interests then needed to be then added to a communication that would be the basis of the 'callback' task for a user.

This is not a fully worked example but is intended to give some ideas on how this can be implemented in a system.

We have two main problems

  1. How do we automatically create a task when a Lead is created?
  2. How do we add a summary of the check box values into the communication?

How do we automatically create a task when a Lead is created?

The first is quite easy. We can use the ideas first introduced in the article "How do I automatically create a reminder task for a user when an opportunity is inserted?".

That article is about creating a communication when an Opportunity is created but this is essentially the same thing.

It uses a PostInsertRecord event function of a Table level on the Lead entity.

We can use the system WhereClause to obtain the details of the newly created lead. Then create a communication record, add the details to communication, save the communication record and create and save the supporting communication link (comm_link) record with the correct details.

The phrase 'add the details to communication' is the second challenge.

How do we add a summary of the check box values into the communication?

Below is a snippet of code that can be used to read the details in the Table Level script as the Lead is entered.

The comment in the code below explain what the script is doing

[code language="javascript"]
//This string will hold the details of the checkbox fields
var stringMessage ="";

//The fields are all contained in the Lead screen 'LeadCustomScreen'
var myBlock = CRM.GetBlock("LeadCustomScreen");
//Screen a enumerable - this allows us to screen all the possible fields quickly
var myE = new Enumerator(myBlock);
while (!myE.atEnd())
{
//The myEntryBlock variable is a convenient way of identifying the individual field being examined
myEntryBlock = myBlock.GetEntry(myE.item());
//not all field properties are available in ServerSide script - some only work in ASP pages
recordFieldInfo = CRM.FindRecord("custom_edits","colp_colname='"+myE.item()+"'");
//This check whether the field is a CheckBox (45) and has data
if (recordFieldInfo.colp_entrytype==45 & & Values(myE.item()))
{
//This builds the string using the correct caption for the user
stringMessage += CRM.GetTrans("ColNames",myEntryBlock) +"="+Values(myE.item())+"
";
}
myE.moveNext();
}
//the string can be then used for what ever purpose
Valid = false;
ErrorStr = stringMessage
[/code]