Changes

Jump to: navigation, search

Custom Field Type: Special – Browser Script

1,116 bytes added, 17:04, 4 December 2018
no edit summary
<u>'''Field Display'''</u> {{JavaScript Syntax}}
This type of field is not displayed. <u>'''==General Description'''</u> ==* 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.
* The 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 Options==All common options:<br />[[Custom Fields - General Information #General_Settings|General Settings]]<br />[[Custom Fields - General Information #Role Field Permissions and Status Field Permissions|Permissions & Availability]]<br />[[Custom Fields - General Information #Classic Options|Classic Options]]<br />For further information, please refer to [[Custom Fields – General Information]].<br /><br />Options listed below are specific to this particular field type. ==Field Display==This type of field is not only displayedwhen ''On Demand'' is selected as a ''Trigger Type''. <u>'''Field OptionsNote:'''</u> 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.
* '''Allow Empty''': N/A* '''Default Text''': N/A* '''Options''': N/A* '''Track Changes''': Yes* '''Store To Value''': N/A <u>'''Special Options for Field'''</u> {{TriggerType}}
* '''JavaScriptCustom Script''' – stores : Stores the procedure you wish to execute. <u>'''Field Validation'''</u>
* '''Type''': N/A* '''JavaScript Validation''': N/A* '''Message''': N/A* '''HTML Tag''': N/A ==Field Permissions==<u>'''[[Role Field Permissions|Role - Field Formatting OptionsPermissions]]'''</u>
* '''Height''': NThese [[Role Field Permissions|fields]] allow you to control by [[Role]] who is allowed to view and/A '''Measure''': '''Default''':* '''Width''': N/A '''Measure''': '''Default''': * '''Number Format''': N/A* '''Style''': N/A* '''Tool Tip''': N/A or modify the field.
<u>'''[[Status Field Permissions|Status - Field Permissions]]'''</u>
 
* ''Only present within the [[Universal Tracking Application]]''
 
These [[Status Field Permissions|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==
<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)''
 Level 1: ''document.'''form1'''.startdate.value''<br/>
Level 2 & 3: ''document.'''frmevent'''.startdate.value''
 * To reference [[Custom Fields]] use cf_xxxxxx where xxxxxx is the field ID<br> Level 1: ''document.'''form1'''.cf_12345.value<br/>
Level 2 & 3: ''document.'''frmevent'''.cf_54321.value''
Instead of using document.form1 at Level 1, and document.frmevent at Levels 2 & 3
you can use the following, which will simply take the first form, so works at any level:
<br />
'''document.forms[0]'''
<u>'''==Examples'''</u> ==(For more examples of scripts see [[:Category:JavaScript Examples]])
'''1. Setting End Date to current date as long as the status is not equal to Closed'''
 <pre>if ([status] != 'Closed')
{
var t=new Date();
}
</pre>
 
 
 
'''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.
<pre>//Set the field that store the total to read only
document.frmeditfrmevent.cf_xxxxxx.readOnly=true;
//Take the value of the passing in field and add it to total sum.
if (index == 1 )
document.frmeditfrmevent.cf_xxxxxx.value=0;
//update the value
document.frmeditfrmevent.cf_xxxxxx.value = parseFloat(document.frmeditfrmevent.cf_xxxxxx.value) + parseFloat(valuetxt);
}
</pre>
'''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.
'''Step 3:''' You will need to go to the Edit view of the Dynamic Data - Dynamic Custom 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. <pre>var expenseCF = new Array('cf_xxxxx1', 'cf_xxxxx2', 'cf_xxxxx3');
var i = 0;
var number= eval("document.frmeditfrmevent."+ expenseCF[0] + ".value;");
number = parseInt(number);
for (i =1; i <= number; i++)
{
var valuetxt = eval("document.frmeditfrmevent."+ expenseCF[i] + ".value;");
if (valuetxt != undefined)
{ //Call the function AddTotal so that it would add the sum together
</pre>
'''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:''' * At {{l1}} use document.form1* At {{l2}} and {{l3}} use document.frmevent* On a [[tabs|tab]] use document.frmedit
==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|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 '''For more examples of scripts seeBrowser Script''' [[:Category:JavaScript Examples]]custom field associated with each portion of script.
==See Also==
* [[Counting Business Days between Two Dates]]
[[Category:Custom Fields]][[Category:JavaScript Examples]]{{CustomFieldPageFooter}}
Smartstaff, administrator
421
edits

Navigation menu