Changes

Jump to: navigation, search

Custom Field Type: Special – Calculated Value

1,619 bytes added, 19:18, 5 September 2018
Undo revision 33084 by ATsim (talk)
=='''General Description'''== {{JavaScript Syntax}}
==General Description==
Executes an expression to calculate a value and store the result.
=='''Field Options'''== {{FieldOptions}}
* '''Allow Empty''': N/A* '''Default Text''': N/A* '''OptionsExpression''': Defines the expression to be executed (additional details on Expressionfound in section below)* '''Track Changes''': Yes{{LabelAboveField}}* '''Store To Value''': N/A{{ToolTip}} {{HideFieldForNewRecord}}=='''Special Options for Field'''== {{SmartFieldView}}
==Expression Field Details=='''Expression''' – defines : 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:
''ParseFloatssParseNum([Total Monthly Cost]) + ParseFloatssParseNum([Total Cost Ex]) + ParseFloatssParseNum([Hardware Rental]) + ParseFloatssParseNum([Email]) + ParseFloatssParseNum([Other])''
<pre>If you are using this field in a "Dynamic Control Field" address the fields by thier their field ids with the following syntax: frm.cf_''customfieldid''cf_customfieldid.value
Example: PARSEFLOATssParseNum(frm.cf_1254625.value)*0.44
</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.{{OptionsTab}}{{Searchable}}{{TrackChanges}}{{HideField}}{{DisableFromGlobalSearch}}
=='''Field Validation'''Formatting== {{FieldFormattingOptions}}
* '''Type''': N/A* '''JavaScript Validation''': N/A* '''Message''': N/A* '''HTML Tag''': N/A =='''Field Formatting Options'''Value Storage== {{ValueStoresTo}}
* '''Height''': N/A '''Measure''': '''Default''':
* '''Width''': N/A '''Measure''': '''Default''':
* '''Number Format''': Yes
* '''Style''': Yes
* '''Tool Tip''': Yes
=='''Notes'''==
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. {{CFPermissionsTab}}
=='''Important Notes on Calculation Order'''==
* 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.
==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|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===
[[Image: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.
===Arithmetic Operators===Example:To round to 3 decimal places, you would use '''Math.round(('''''expression''''')*1000)/1000'''
[[Image*** For no decimal places:CS08**** '''Math.pnground('''''expression''''')'''where ''expression'' is the calculation to be rounded off, such as PARSEINT([variable 1])/PARSEINT([variable 2])
===String Operators===
 
[[Image:CS081.png]]
===Comparison Operators===
 
[[Image:CS084.png]]
===Date Functions===
[[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([Image:CS085date 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.png]'''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)''
**** ''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:
**** [[Image:CS086''fieldname''].png]]length [[CategoryTo show the number of words in a text field, use:Custom Fields]] ===See Also===[[How Calculated Custom Fields Work]]
**** [''fieldname''].split(" ").length==See Also==**** [[How Calculated Custom Fields Work]]**** [[ssParseNum]]**** [[Template Formulas/ Type Formula]]**** [[:Category:JavaScript]]**** [[Variable List]]**** [[The Musings of Chin - Correct Variable Processor Use]]**** Disambiguation: [[Calculated Field|Calculated Field in Reporting]]{{CustomFieldPageFooter}}
0
edits

Navigation menu