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.
- Click <My Profile> | Administration | Customization | Primary Entities | Company.
- Click the Screens tab. A list of customizable screens for the Company entity is displayed.
- Click the Company Entry Screen.
- Highlight Company : Status.
- 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. - Click Update and then click Save.
- 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.
- 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.
- Click the Company Entry Screen.
- Highlight Company:Type.
- 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. - Click Update and then click Save.
- 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.
- Click Company Entry Screen.
- Highlight Company: Status.
- Enter the following script in CreateScript:
if(CurrentUser.user_logon=='Admin')
{
RemoveLookup('Archive');
}
- 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.