Difference between revisions of "Custom Field Type: Special – Browser Script"

From SmartWiki
Jump to: navigation, search
m (Reverted edits by AlvinT (talk) to last revision by Arthur Lathrop)
Line 2: Line 2:
 
{{JavaScript Syntax}}
 
{{JavaScript Syntax}}
  
<u>'''Field Display'''</u>
+
==General Description==
 
 
This type of field is only displayed when ''On Demand'' is selected as a ''Trigger Type''.
 
 
 
'''Note:''' If there is a browser script on a Tab, and the script does not have any visibility conditions on it, the Tab will be displayed even if there are no other visible fields on it.
 
 
<u>'''General Description'''</u>
 
  
 
* This field type adds a '''[[JavaScript]]''' to the page on which it is located.
 
* This field type adds a '''[[JavaScript]]''' to the page on which it is located.
Line 14: Line 8:
 
* This field type is used by programmers to create enhanced functionality.
 
* This field type is used by programmers to create enhanced functionality.
 
* In general, Browser Scripts must be at the end of the page, so should be included sequentially at the end of your list of [[Custom Fields]].
 
* In general, Browser Scripts must be at the end of the page, so should be included sequentially at the end of your list of [[Custom Fields]].
 +
 +
==Field Display==
 +
 +
This type of field is only displayed when ''On Demand'' is selected as a ''Trigger Type''.
 +
 +
'''Note:''' If there is a browser script on a Tab, and the script does not have any visibility conditions on it, the Tab will be displayed even if there are no other visible fields on it.
  
 
{{FieldOptions}}
 
{{FieldOptions}}
 +
{{TriggerType}}
 +
* '''JavaScript''': Stores the procedure you wish to execute
 +
 +
{{ButtonLabel}}
 +
 
{{HideFieldForNewRecord}}
 
{{HideFieldForNewRecord}}
 
<u>'''Special Options for Field'''</u>
 
  
{{TriggerType}}
 
  
'''JavaScript''': Stores the procedure you wish to execute
+
{{OptionsTab}}
+
{{DisableFromGlobalSearch}}
<u>'''Services'''</u>
+
 
  
* '''Enable Map Service''': displays the map icon next to the field name that will launch the user’s selected map service and display a map of the content of the field
+
{{CFPermissionsTab}}
* '''Enable People Search Service''': displays the search Internet icon next to the field name that will launch a variety of search services and display the contact details from those services
 
* '''Enable Organization Search Service''': displays the search Internet icon next to the field name that will launch a variety of search services and display the organisations details from those services
 
  
  
 +
==Field Permissions==
 
<u>'''[[Role Field Permissions|Role - Field Permissions]]'''</u>
 
<u>'''[[Role Field Permissions|Role - Field Permissions]]'''</u>
  
Line 40: Line 41:
  
  
 +
==Referencing Other Fields==
 
<u>'''Referencing Other Fields'''</u>
 
<u>'''Referencing Other Fields'''</u>
 
* Standard Fields can be referenced by name ''(see [[Web Page View Field Variables|this]] page for a list of standard field variable names)''
 
* Standard Fields can be referenced by name ''(see [[Web Page View Field Variables|this]] page for a list of standard field variable names)''
Line 51: Line 53:
  
  
<u>'''Examples'''</u> (For more examples of scripts see [[:Category:JavaScript]])
+
==Examples==
 +
(For more examples of scripts see [[:Category:JavaScript]])
  
 
'''1. Setting End Date to current date as long as the status is not equal to Closed'''
 
'''1. Setting End Date to current date as long as the status is not equal to Closed'''

Revision as of 15:26, 19 February 2016

Click here to peruse our selection of custom fields.
This feature uses JavaScript syntax
Text code javascript.gif

General Description

  • This field type adds a JavaScript to the page on which it is located.
  • This script will execute whenever the page is saved.
  • This field type is used by programmers to create enhanced functionality.
  • In general, Browser Scripts must be at the end of the page, so should be included sequentially at the end of your list of Custom Fields.

Field Display

This type of field is only displayed when On Demand is selected as a Trigger Type.

Note: If there is a browser script on a Tab, and the script does not have any visibility conditions on it, the Tab will be displayed even if there are no other visible fields on it.

Field Options

Option Description Format
Custom Field ID The unique ID number associated with the custom field. Not Applicable
Field Type The list of available Field Types. @fieldtype@
Field Name The name of the field, used internally to reference the user's input; @fieldname@
Caption  The leading question or prologue before the field. @caption@
Display Order  The order (relative to other fields) in which this field is displayed. @displayorder@
Description Definition and general description of the custom field. Will not be displayed. @description@
  • Trigger Type: This setting is unique to Browser Script fields and works in conjunction with System Calls. The options are:
  • On Page - The JavaScript defined in the Custom Script section will be loaded and functions defined therein can be called by other fields on the page.
  • On Demand - The JavaScript or System Call is executed by the server when the user clicks a button on the page. The button will be displayed for the Browser Script field when you select this type of trigger. As a result, a few extra settings are displayed when the Trigger Type is flipped to On Demand.

Note: Only Browser Script fields set to On Demand have any visibility on a page. On Load - Only System Calls can be used with this trigger type. The System Call will be processed server-side when the page is requested ("loaded").

  • On Save - Only System Calls can be used with this trigger type. The System Call will be processed server-side when the page is saved.
  • JavaScript: Stores the procedure you wish to execute
  • Button Label: Text to be displayed on the field's button. If no text is entered, the system will use a default label.
  • On New Record: Controls how the field should be displayed until record has been saved once.
    • Always Display: Field will be exposed both before and after the record is saved.
    • Hide on New Record: Field will be hidden until record is saved.
    • Only Show on New Record: Field will be exposed until record is saved, and then it will be hidden. This option is useful for fields that provide instructions for filling out forms before saving.


Options

General Options

  • Disable Field From Global Search: Selecting this option means that the contents of this field will not be displayed in Global Search results.


Permissions & Availability Tab


Field Permissions

Role - Field Permissions

These fields allow you to control by Role who is allowed to view and/or modify the field.

Status - Field Permissions

These fields allow you to control by the Status of the record whether or not the field can be viewed and/or modified.


Referencing Other Fields

Referencing Other Fields

  • Standard Fields can be referenced by name (see this page for a list of standard field variable names)

Level 1: document.form1.startdate.value
Level 2 & 3: document.frmevent.startdate.value


  • To reference Custom Fields use cf_xxxxxx where xxxxxx is the field ID

Level 1: document.form1.cf_12345.value
Level 2 & 3: document.frmevent.cf_54321.value


Examples

(For more examples of scripts see Category:JavaScript)

1. Setting End Date to current date as long as the status is not equal to Closed

if ([status] != 'Closed')
{ 
var  t=new Date();
var year = t.getFullYear();
var mon = t.getMonth() + 1; 
var day = t.getDate();
document.form1.enddate.value=year+'-'+mon+'-'+day;
} 


2. How to calculate sum of Dynamic Custom Field

****The following instructions are for those who have Global System Administrator only. Please contact your system administrator before proceeding. ****

You will need to create in total three custom fields. Two custom fields that will be display before (having a smaller display order than) the Dynamic Custom Field (i.e if the dynamic custom field have display order of 2050 then the two custom fields display order have to be smaller than 2050 like 2045 and 2047). One custom fields will be located within the dynamic custom field.

Step 1: Create the 1st custom field using type "Text box - Single Line" that will be store the value of the sum or total. You need to remember the Field ID of this custom field before proceeding to step 2. The Field ID is located in the last column of the "Field List" view.

Step 2: Create the 2nd custom field using type "Special - Browser Script" and paste the following script into the Javascript text box. Replace the "xxxxxx" with the Field ID of the 1st Custom Field that you just created.

//Set the field that store the total to read only

document.frmevent.cf_xxxxxx.readOnly=true;

//Take the value of the passing in field and add it to total sum.

function addTotal(valuetxt,index) 
{  
   // the index is equal to 1 then reset the sum value to zero

  if (index == 1 ) 
     document.frmevent.cf_xxxxxx.value=0;

  //update the value

   document.frmevent.cf_xxxxxx.value = parseFloat(document.frmevent.cf_xxxxxx.value) +  parseFloat(valuetxt); 
} 


Step 3: You will need to go to the Edit view of the Dynamic Data - Dynamic Control Field and create a new sub field. Create this 3rd custom field using type "Special - Browser Script" and paste the following script into the Javascript text box. Replace "xxxxx1" with the field id of the Dynamic Data - Dynamic Custom Field. Replace "xxxxx2" and "xxxxx3" with field id of all the fields that you need to sum up.

var expenseCF = new Array('cf_xxxxx1', 'cf_xxxxx2', 'cf_xxxxx3');
var i = 0;
var number= eval("document.frmevent."+ expenseCF[0] + ".value;");
number = parseInt(number);

for (i =1; i <= number; i++)
{
  var valuetxt = eval("document.frmevent."+ expenseCF[i] + ".value;");
  if (valuetxt != undefined)
  {  //Call the function AddTotal so that it would add the sum together
      addTotal(valuetxt,i);
  } 
}

NOTE: If you want the total to display at the bottom of the dynamic field, you need to create a new field and assign the value of the original total to the new custom field that you just create.


NOTE:

Note

A comment is automatically added at the start of any browser scripts when they are added to the page which states the custom field ID of the browser script.

  • Displays as:
// Browser script cf_123456
  • When viewing the source of a page this will facilitate identifying the Browser Script custom field associated with each portion of script.

See Also