The calculated component is used to display a calculation in a field. All calculations are performed on the fly when the component is rendered and saved to the InstanceData if the new calculation is different from what’s saved.
Below are examples of what each calculation looks like:
Component Code
The first section of the code are the variables used to display calculations and store their values. Below are the various methods used in the calculated component.
OnParametersSetAsync()
This method is triggered when the component is first loaded and if the parent component is updated. This method assigns the XMLName variable and calls DisplayCalculation() which will populate the remaining component variables depending on the calculation type. This call is only made if a calculation type and XMLName is specified in the FieldDefinition parameter.
DisplayCalculation()
This method is called to display a calculation. It’s comprised of a single switch statement that checks the value of the calculation type that’s specified in the field definition. Once the calculation has been made XML is generated and added to the InstanceData if the calculation result differs from what already exists in the InstanceData.
Below are all the calculations, how they’re calculated, and the format of the XML that’s saved:
Created By
Pulls and displayed the value of the CreatedBy property of the current instance.
<CalcualtedFieldName>Dylan Sprague</CalculatedFieldName>
Created On
Pulls and displays the value of the CreatedOn property of the current instance and formats the value in a 24-Hour date format. YYYY-MM-DD HH:MM:SS.
<CalcualtedFieldName>2021-12-13 13:31:51</CalculatedFieldName>
Inserted By
Pulls and displayed the value of the InsertedBy property of the current instance.
<CalcualtedFieldName>Dylan Sprague</CalculatedFieldName>
Inserted On
Pulls and displays the value of the InsertedOn property of the current instance and formats the value in a 24-Hour date format. YYYY-MM-DD HH:MM:SS.
<CalcualtedFieldName>2021-12-13 13:31:51</CalculatedFieldName>
External URL
Pulls and displays the value of the TargetPageURL and TargetPageName fields from the field definition. If no TargetPageName is specified, then it will default to the same value as the TargetPageURL.
<CalcualtedFieldName TargetPageName="https://www.greatideaz.com/">Home v2.23</CalculatedFieldName>
Invite User Link
Generates an invite user link which is comprised of the base URL of the website and the InstanceGUID of the current instance.
A join key is also generated which is just the InstanceGUID of the current instance.
For Example:
- Invite Link
- https://www.trellispark.com/00000000-0000-0000-0000-000000000000
- Join Key
- 00000000-0000-0000-0000-000000000000
<CalcualtedFieldName JoinKey="00000000-0000-0000-0000-000000000000"> https://www.trellispark.com/00000000-0000-0000-0000-000000000000 </CalculatedFieldName>
Join Workspace Link
Pulls and parses the InstanceData of the current instance in search of a WorkspaceGUID element. If one is found a join workspace link is generated using the base URL of the website and the value of the WorkspaceGUID element.
For Example:
- Join Workspace Link
- https://www.trellispark.com/00000000-0000-0000-0000-000000000000
If no WorkspaceGUID element is found, then the calculation cannot be completed.
<CalcualtedFieldName> https://www.trellispark.com/00000000-0000-0000-0000-000000000000 </CalculatedFieldName>
Show InstanceGUID
Pulls and displayed the value of the InstanceGUID property of the current instance.
<CalcualtedFieldName>00000000-0000-0000-0000-000000000000</CalculatedFieldName>
Feedback Instance Link
Pulls and parses the InstanceData of the current instance in search of a FeedbackInstanceData element. If one is found a button is displayed what when selected will load the instance the feedback was submitted on. If a FeedbackInstanceData element is not found the calculation cannot be completed and a message stating so is displayed.
The text on the button will use the following syntax: FormName – InstanceName
For example: Customer – GreatIdeaz
<CalcualtedFieldName> <FeedbackOnInstanceGUID> 00000000-0000-0000-0000-000000000000 </FeedbackOnInstanceGUID> <FeedbackOnFormDefinitionGUID> 00000000-0000-0000-0000-000000000000 </FeedbackOnFormDefinitionGUID> <FeedbackOnInstanceName>Dylan Sprague</FeedbackOnInstanceName> <FeedbackOnFormName>Customer</FeedbackOnFormName> </CalculatedFieldName>
FeedbackLinkClicked()
This method is called the the button produced by the feedback calculation is selected. The purpose of this method is to save the current instance then navigate to the instance the feedback was submitted on.