The Values() collection

Hints, Tips and Tricks

Technical Hints Tips and Tricks that cover customization and development using Sage CRM. API usage and coding are covered.

The Values() collection

  • Comments 5
  • Likes

The Values() collection can be used in all serverside scripts to examine the passed in Values from a form. 

  • Create Scripts
  • Validate Scripts
  • Tablelevel Scripts
  • Workflow Scripts

The Values() collection must always have an argument passed to it.
The Values() collection can not be examined using a for...in statement or used directly with an enumerator.

Using the example of the CommunicationSchedulingBox

If in a validation script you examine the value of a field with a value defined, e.g.

Valid = false;
ErrorStr=Values('cmli_comm_userid');

The value is returned.

If you examine the value of a field without a value defined, e.g.

Valid = false;
ErrorStr='comm_taskreminder='+Values('comm_taskreminder');

The value is reported as 'undefined'.

If you examine the value of a field that does not exist on the form, e.g.

Valid = false;
ErrorStr='comm_notafield='+Values('comm_notafield');

The value is also reported as 'undefined'.

There is no way of distinguishing between a field that does not exist on the form and one that exists but does not have a value to pass.

To enumerate Values() for a particular screen we can do the following: (Code can be entered into the validation script of a field in the CommunicationSchedulingBox).

Valid = false;
ErrorStr ='';
var CommunicationSchedulingBox = CRM.GetBlock('CommunicationSchedulingBox');
var myE = new Enumerator(CommunicationSchedulingBox);
while (!myE.atEnd())
{
ErrorStr += myE.item()+'='+Values(myE.item())+'<br>';
myE.moveNext();
}

This is only a partial solution and does not include hidden fields that are not defined within the block, CommunicationSchedulingBox.

You can use the FormValues() collection to access all fields on a page as the Values() collection only returns the fields that are in the block not the fields in the html <Form>.

Where a field is a multi select (e.g. cmli_comm_userid) then it is only possible to obtain the first value with Values('cmli_comm_userid').

In a table level script you can also extend the Values() collection for the current table

Comments