Create script examples

Example 1

You can add a Create Script, which automatically sets the Company Status to None when a user, whose Primary Team is Direct Sales, creates a new company. You must attach Create Scripts to the field that they are to act on.

  1. Click <My Profile> | Administration | Customization | Primary Entities | Company.
  2. Click the Screens tab. A list of customizable screens for the Company entity is displayed.
  3. Click the Company Entry Screen.
  4. Highlight Company : Status.
  5. Enter the following script into CreateScript. This script assumes that the primarychannelid (primary team id) for the Direct Sales team is equal to 1.

    if(CurrentUser.user_
    primarychannelid==1)
    {
    DefaultValue='None';
    }
    The DefaultValue property can only be set when a new record is created, or in a field created by a workflow action.
  6. Click Update and then click Save.
  7. Log off and back on as any user whose Primary Team is Direct Sales. Note that you do not need to log off for the script to be activated, but you need to be in the Direct Sales team to see the effect.
  8. Select New to create a new company. Status is automatically set to None.

Example 2

This example adds a Create Script, which automatically sets a new company type to Competitor and makes this field read only when William Dolan (DolanW) creates the company.

  1. Click the Company Entry Screen.
  2. Highlight Company:Type.
  3. Enter the following script in CreateScript :

    if(Values("Act")==1200)
    {
    if(CurrentUser.user_logon=='DolanW')
    {
    DefaultValue='Competitor';
    ReadOnly=true;
    }
    }
    The if(Values("Act")==1200) statement checks that the System Action is being used. This is required to make the script apply during insertion only. Without this statement, the script will work for updates, which means that the field in the screen is always locked down as read only for the user. This script assumes that deduplication is enabled. Check in <My Profile> | Administration | System | System Behavior that Deduplicationis set to Yes.
  4. Click Update and then click Save.
  5. Log on as William Dolan. When you create a new company, the Type field is automatically set to Competitor and is read only.

Example 3

This example adds a Create Script, which removes the Archive selection item from the Company Status list when the System Administrator (Admin) creates a new company.

  1. Click Company Entry Screen.
  2. Highlight Company: Status.
  3. Enter the following script in CreateScript:

    if(CurrentUser.user_logon=='Admin')
    {
    RemoveLookup('Archive');
    }
  1. Log in as the system administrator. When you create or update a new company, the Archive option is no longer available on the Status list.
The scripts in Examples 2 and 3 work in conjunction with whatever access settings may have been defined in the Field Security interface because in both cases the scripts are restricting access to the fields rather than widening it. In contrast, a script that specifies write access to a field depending on the user’s ID will not take effect if that user has already been denied access in the Field Security interface.