Using Conditions and Functions in Viewer

Understanding Conditions and Functions in Viewer

Introduction

Conditions and functions in Viewer play a crucial role in creating logic and interactivity within the application. They allow developers to define rules and actions based on certain parameters, enabling them to customize the behavior of the application according to specific scenarios.

Commonly Used Functions in Viewer

There are several commonly used functions in Viewer that help developers manipulate data, control the flow of the application, and perform calculations. Some of the most popular functions include:

{{isTruthy}}

Returns a true result when the provided value is considered truthy.
Works with Array , Object and Fields

Example: If Case.Total_Loss_Reason__c have value , then show it , else write "N/A"

{{#isTruthy Case.Total_Loss_Reason__c}} {{Case.Total_Loss_Reason__c }}{{else}}N/A{{/isTruthy}}

############# Can also hide table or any section

{{#isTruthy Case.Total_Loss_Reason__c}} 
  .. Insert Table ..
{{else}}
  N/A
{{/isTruthy}}

{{#EQ}}

This function is a helper that checks if two values, a and b, are equal. If a and b are equal, the function show the block of template code nested within the helper. If a and b are not equal, the function does not render the block and show the else if avaliable.

Example: If case Total_Loss_Reason__c is equal to 'Beyond Economic Repair' write 'Positive' alse 'N/A'

{{#eq Case.Total_Loss_Reason__c 'Beyond Economic Repair' }}
Positive
{{else}}
N/A
{{/eq}}

############# Can also hide table or any section

{{#eq Case.Total_Loss_Reason__c 'Beyond Economic Repair' }}
 .. Insert Table ..
{{else}}
N/A
{{/eq}}

Tips for Efficient Coding with Conditions and Functions

  1. Case Sensitivity: Be aware that some languages and systems are case-sensitive. This means that 
  2. Use Open and Close Hash (# /): In some templating languages, the hash symbol (#) is used to denote special blocks of code, such as conditional blocks or loops. These blocks are typically closed with a forward slash (/). For example, 
  3. Use Single Quotes to Mark as String: When specifying a string of text, it's common to enclose the text in single quotes ('). This tells the system that the enclosed text should be treated as a single unit, even if it contains spaces or special characters. For example, 'Hello, world!' is a single string. Always use quotes when working with strings.

Was this article helpful?

Query Data: Viewer Tips
Date Formats and Date Manipulation Techniques in Viewer
Feedback