Difference between revisions of "Custom Field Type: Special – Calculated Value"

From SmartWiki
Jump to: navigation, search
(Other Functions)
(Undo revision 33084 by ATsim (talk))
 
(31 intermediate revisions by 6 users not shown)
Line 1: Line 1:
'''General Description'''
+
{{JavaScript Syntax}}
  
 +
==General Description==
 
Executes an expression to calculate a value and store the result.
 
Executes an expression to calculate a value and store the result.
  
<u>'''Field Options''' </u>
+
{{FieldOptions}}
  
* '''Display Order''': The order (relative to other fields) in which this field is displayed
+
* '''Expression''': Defines the expression to be executed (additional details on Expression found in section below)
* '''Tab Name''': Displays the field under a given tab
+
{{LabelAboveField}}
* '''Field Name''': The name of the field, used internally to reference the user's input
+
{{ToolTip}}
* '''[[Caption]]''': The leading question or prologue before the field
+
{{HideFieldForNewRecord}}
* '''Searchable''': This field can be searched within the tracking application
+
{{SmartFieldView}}
* '''Track Changes''': Keeps track of changes made to this field
 
 
<u>'''Special Options for Field'''</u>
 
  
 +
==Expression Field Details==
 
'''Expression''': Defines the expression to be executed
 
'''Expression''': Defines the expression to be executed
  
All values are treated as strings. For arithmetic operations, PARSEINT and PARSEFLOAT functions are used to convert the string value to a numeric value.
+
All values are treated as strings. For arithmetic operations, PARSEINT and PARSEFLOAT functions are used to convert the string value to a numeric value.
  
 
Example summing the values using five custom fields:
 
Example summing the values using five custom fields:
  
''ParseFloat([Total Monthly Cost]) + ParseFloat([Total Cost Ex]) + ParseFloat([Hardware Rental]) + ParseFloat([Email]) + ParseFloat([Other])''
+
''ssParseNum([Total Monthly Cost]) + ssParseNum([Total Cost Ex]) + ssParseNum([Hardware Rental]) + ssParseNum([Email]) + ssParseNum([Other])''
  
<pre>
+
<pre>If you are using this field in a "Dynamic Control Field" address the fields by their field ids with the following syntax:
If you are using this field in a "Dynamic Control Field" address the fields by thier field ids with the following syntax:
 
 
   frm.cf_customfieldid.value  
 
   frm.cf_customfieldid.value  
  
Example: PARSEFLOAT(frm.cf_1254625.value)*0.44
+
Example: ssParseNum(frm.cf_1254625.value)*0.44
 
</pre>
 
</pre>
  
'''Note''': You can in general use either the name of the field within square brackets, or frm.cf_''customfieldid''.value to refer to the values for the calculations.<br>
+
{{OptionsTab}}
The limitation in both cases is that the field must be visible on the page.
+
{{Searchable}}
 +
{{TrackChanges}}
 +
{{HideField}}
 +
{{DisableFromGlobalSearch}}
  
<u>'''Services'''</u>
+
==Formatting==
 +
{{FieldFormattingOptions}}
  
* '''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
+
==Value Storage==
* '''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
+
{{ValueStoresTo}}
* '''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
 
  
<u>'''Field Formatting Options'''</u>
 
  
* '''Number Format''': Formats any numbers entered into this field
+
{{CFPermissionsTab}}
* '''Style''': '''Bold''', <u>Underline</u>, ''Italic'', <font color="red">Highlight</font>
 
* '''[[Tool Tip]]''': Enter help text to be shown on mouse-over
 
* '''Read Only''': Checkbox
 
* '''HTML Tag''': Additional attributes to the field HTML tag
 
* '''[[Visibility Condition]]''': Conditions upon which the field is visible
 
  
<u>'''[[Role Field Permissions|Role - Field Permissions]]'''</u>
 
  
These [[Role Field Permissions|fields]] allow you to control by [[Role]] who is allowed to view and/or modify the field.
 
  
<u>'''[[Status Field Permissions|Status - Field Permissions]]'''</u>
+
==Notes==
* ''Only present within the [[Universal Tracking Application]]''
+
* You can in general use either the name of the field within square brackets, or frm.cf_''customfieldid''.value to refer to the values for the calculations.
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.
+
* In both cases is that the field must be visible on the page (or a [[Hidden Value]] custom field that is on the page).
+
* A [[Combo Box]] custom field can be used in mathematical as long as the stored value is numeric. The displayed value does not have to be numeric
'''Notes'''
+
* [[Check Boxes]] cannot normally be used in Calculated Value fields. (They can be accommodated with sufficient knowledge of JavaScript)
  
You can use arithmetic, string, comparison operators and functions within the calculated [[Custom Field|custom field]].
 
* References to other fields are always enclosed in square brackets: [variable1]
 
* The calculations are performed when you click the '''Save''' button and save the page.
 
  
=='''Important Notes on Calculation Order'''==
+
You can use arithmetic, string, comparison operators and functions within the calculated [[Custom Field|custom field]].
  
* Calculated field formulas are executed in the same order that the calculated fields are displayed on the page.
+
* References to other fields are always enclosed in square brackets: [variable1]
* You must not place fields that perform summary calculations based on other calculated fields ABOVE the subordinate calculations.
+
* The calculations are performed when you click the '''Save''' button and save the page.
* If the fields are ordered in this manner, saving the page will not update the summary calculation, as summary formula will be executed BEFORE the subordinate calculations are performed.
 
  
 +
 +
 +
* Calculated field formulas are executed in the same order that the calculated fields are displayed on the page.
 +
* You must not place fields that perform summary calculations based on other calculated fields ABOVE the subordinate calculations.
 +
** If the fields are ordered in this manner, saving the page will not update the summary calculation, as summary formula will be executed BEFORE the subordinate calculations are performed.
 
==SmartSimple Calculated Field Operators==
 
==SmartSimple Calculated Field Operators==
 +
===Arithmetic Operators===
 +
[[Image:CS08.png]]
  
===Arithmetic Operators===
+
'''Rounding''':
 +
 
 +
** To round a calculation to 2 decimal places use the following syntax:
 +
*** '''Math.round(('''''expression''''')*100)/100'''
 +
'''Note:''' To round to a different decimal place just change '''*100)/100''' part as per requirement.
 +
 
 +
Example:To round to 3 decimal places, you would use '''Math.round(('''''expression''''')*1000)/1000'''
  
[[Image:CS08.png]]
+
*** For no decimal places:
 +
**** '''Math.round('''''expression''''')'''
 +
where ''expression'' is the calculation to be rounded off, such as PARSEINT([variable 1])/PARSEINT([variable 2])
  
 
===String Operators===
 
===String Operators===
 
 
[[Image:CS081.png]]
 
[[Image:CS081.png]]
  
 
===Comparison Operators===
 
===Comparison Operators===
 
 
[[Image:CS084.png]]
 
[[Image:CS084.png]]
  
 
===Date Functions===
 
===Date Functions===
 +
[[Image:CS085.png]]
  
[[Image:CS085.png]]
+
'''calage([date of birth])''' - Calculates the number of full years between the current date and the date included in the function.
 +
'''calage([date of birth],1)''' - Calculates the number of years and months between the current date and the date included in the function as a floating point.
 +
'''calage([date of birth],2)''' - Calculates the number of years and months between the current date and the date included in the function as the string "X years and Y months".
  
 
===Time Functions===
 
===Time Functions===
 
 
To calculate the time difference for '''Standard Fields''' in hours and minutes use the following
 
To calculate the time difference for '''Standard Fields''' in hours and minutes use the following
  
 
Level 1:
 
Level 1:
* ''timediff(frm.ostartdate.value,frm.oenddate.value,frm.ostarthour.value,frm.ostartminute.value,frm.oendhour.value,frm.oendminute.value)''
+
 
 +
**** ''timediff(frm.ostartdate.value,frm.oenddate.value,frm.ostarthour.value,frm.ostartminute.value,frm.oendhour.value,frm.oendminute.value)''
 
Level 2:
 
Level 2:
* ''timediff(frm.startdate.value,frm.enddate.value,frm.starthour.value,frm.startminute.value,frm.endhour.value,frm.endminute.value)''
 
  
 +
**** ''timediff(frm.startdate.value,frm.enddate.value,frm.starthour.value,frm.startminute.value,frm.endhour.value,frm.endminute.value)''
 
(note: the starttime and endtime '''Standard Fields''' are actually stored as part of the startdate and enddate fields, which is why they are used here)
 
(note: the starttime and endtime '''Standard Fields''' are actually stored as part of the startdate and enddate fields, which is why they are used here)
  
 +
===Other Functions===
 +
To show the number of characters in a text field, use:
  
 +
**** [''fieldname''].length
 +
To show the number of words in a text field, use:
  
[[Category:Custom Fields]]
+
**** [''fieldname''].split(" ").length
 
+
==See Also==
===See Also===
+
**** [[How Calculated Custom Fields Work]]
[[How Calculated Custom Fields Work]]
+
**** [[ssParseNum]]
 
+
**** [[Template / Type Formula]]
[[Template Formulas]]
+
**** [[:Category:JavaScript]]
 
+
**** [[Variable List]]
[[:Category:JavaScript Examples|JavaScript Examples]]
+
**** [[The Musings of Chin - Correct Variable Processor Use]]
 +
**** Disambiguation: [[Calculated Field|Calculated Field in Reporting]]
 +
{{CustomFieldPageFooter}}

Latest revision as of 15:18, 5 September 2018

This feature uses JavaScript syntax
Text code javascript.gif

General Description

Executes an expression to calculate a value and store the result.

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@


  • Expression: Defines the expression to be executed (additional details on Expression found in section below)
  • Label Display: Determines the location of the field caption. Options include: Left of Field, Above Field, No Caption, Hide Caption. Note: this option was previously called Label Display. (See examples here.)
  • Tool Tip: When the user hovers their mouse pointer over the caption of a field, the text in this section will appear.
  • 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.
  • SmartField View - Include or exclude this field from SmartField Views (@SmartFields@) or only display this field for SmartField Views. See SmartField View for further details.

Expression Field Details

Expression: Defines the expression to be executed

All values are treated as strings. For arithmetic operations, PARSEINT and PARSEFLOAT functions are used to convert the string value to a numeric value.

Example summing the values using five custom fields:

ssParseNum([Total Monthly Cost]) + ssParseNum([Total Cost Ex]) + ssParseNum([Hardware Rental]) + ssParseNum([Email]) + ssParseNum([Other])

If you are using this field in a "Dynamic Control Field" address the fields by their field ids with the following syntax:
  frm.cf_customfieldid.value 

Example: ssParseNum(frm.cf_1254625.value)*0.44

Options

General Options

  • Searchable: This field can be searched within the tracking application.
  • Track Changes: Keeps track of changes made to this field.
  • Hide Field: Field will be hidden.
  • Disable Field From Global Search: Selecting this option means that the contents of this field will not be displayed in Global Search results.

Formatting

Value Storage

  • Value Storage: Enables linking two different custom fields to the same user data. See Value Stores To page.


Permissions & Availability Tab


Notes

  • You can in general use either the name of the field within square brackets, or frm.cf_customfieldid.value to refer to the values for the calculations.
  • In both cases is that the field must be visible on the page (or a Hidden Value custom field that is on the page).
  • A Combo Box custom field can be used in mathematical as long as the stored value is numeric. The displayed value does not have to be numeric
  • Check Boxes cannot normally be used in Calculated Value fields. (They can be accommodated with sufficient knowledge of JavaScript)


You can use arithmetic, string, comparison operators and functions within the calculated custom field.

  • References to other fields are always enclosed in square brackets: [variable1]
  • The calculations are performed when you click the Save button and save the page.


  • Calculated field formulas are executed in the same order that the calculated fields are displayed on the page.
  • You must not place fields that perform summary calculations based on other calculated fields ABOVE the subordinate calculations.
    • If the fields are ordered in this manner, saving the page will not update the summary calculation, as summary formula will be executed BEFORE the subordinate calculations are performed.

SmartSimple Calculated Field Operators

Arithmetic Operators

CS08.png

Rounding:

    • To round a calculation to 2 decimal places use the following syntax:
      • Math.round((expression)*100)/100

Note: To round to a different decimal place just change *100)/100 part as per requirement.

Example:To round to 3 decimal places, you would use Math.round((expression)*1000)/1000

      • For no decimal places:
        • Math.round(expression)

where expression is the calculation to be rounded off, such as PARSEINT([variable 1])/PARSEINT([variable 2])

String Operators

CS081.png

Comparison Operators

CS084.png

Date Functions

CS085.png

calage([date of birth]) - Calculates the number of full years between the current date and the date included in the function. calage([date of birth],1) - Calculates the number of years and months between the current date and the date included in the function as a floating point. calage([date of birth],2) - Calculates the number of years and months between the current date and the date included in the function as the string "X years and Y months".

Time Functions

To calculate the time difference for Standard Fields in hours and minutes use the following

Level 1:

        • timediff(frm.ostartdate.value,frm.oenddate.value,frm.ostarthour.value,frm.ostartminute.value,frm.oendhour.value,frm.oendminute.value)

Level 2:

        • timediff(frm.startdate.value,frm.enddate.value,frm.starthour.value,frm.startminute.value,frm.endhour.value,frm.endminute.value)

(note: the starttime and endtime Standard Fields are actually stored as part of the startdate and enddate fields, which is why they are used here)

Other Functions

To show the number of characters in a text field, use:

        • [fieldname].length

To show the number of words in a text field, use:

        • [fieldname].split(" ").length

See Also