Using functions

You can use functions in various places in Senta: 


In placeholders -- useful for formatting placeholders in special ways, e.g. by formatting text.

In date offsets -- handy for choosing dates in more complex ways, e.g. the earliest of two dates.


Available functions

The following functions are available in Senta:


IF

IF/ELSE

FIXED

TRIM

LOWER

UPPER

EARLIEST

LATEST

RAND, RANDBETWEEN, CHOOSE

REMOVESPACES

SUBSTITUTE

DATEFORMAT


Any of the described functions must be enclosed within curly braces { } when used within a placeholder.


IF


Lets you put in different text, dates, numbers, etc. based on a condition.


IF (condition, value1, value2)


IF (client.taxnumber <> "", "We have your tax number on file.", "We do not have your tax number on file yet.")

IF (client.priority = 1, +3d, +2w)


The IF function supports the following operators: 


= equals

<> does not equal

!= (this is the same as the <> above)

< is less than

> is greater than

<= is less than or equal to

>= is greater than or equal to



IF/ELSE


You can now use the function {if}...{else}...{endif} which allows you to have two different options for text in your emails, for example:


{IF (client.clienttype = "Individual")} 

Your self assessment tax return is due...


{ELSE} 


Your corporation tax return is due...


{ENDIF}



CONTAINS


Allows you to insert set text if a specific term is used within a field.


IF (CONTAINS(client.software, "Xero"), "We will access Xero to retrieve your accounting records.","Please upload your records to the client portal as soon as possible.")


EMBEDDED PLACEHOLDERS


You can use placeholders in the format {client.title} within other placeholders.


IF (client.language = "French", "Je vous écris au sujet de votre entreprise {client.title}", "I am writing to you regarding your company {client.title}")


FIXED


Shows a number with comma-separated thousands and a fixed number of decimal places


FIXED (number, places)


FIXED (1000, 2) would show 1,000.00


TRIM


Removes excess spaces from text.


TRIM (text)


TRIM("Hello    ") would not show the spaces after Hello.


LOWER


Changes text to lower case.


LOWER (text)


LOWER ("ACCOUNTS") would show "accounts"


UPPER


Changes text to upper case.


UPPER (text)


UPPER ("payroll") would show "PAYROLL"


EARLIEST


Picks the earliest of two dates.  The two dates can be field references or date offsets.


EARLIEST (date1, date2)


EARLIEST (job.previous_task_completion, duedate-30d)


LATEST


Picks the latest of two dates.  The two dates can be field references or date offsets.


LATEST (date1, date2)


LATEST (job.previous_task_completion, duedate-30d)


RAND, RANDBETWEEN, CHOOSE


Useful for generating random numbers, for example these can be used to randomly assign clients to an account manager.


RAND() gives you a random number greater than or equal to 0 and less than but not equal to 1.


RANDBETWEEN() gives you a random integer between your two values, inclusive, i.e. greater than or equal to the first number, and less than or equal to the second number


Randomly choose between 2 options:

CHOOSE( RANDBETWEEN( 1, 2 ), "Option A", "Option B" )


Randomly select a user:

CHOOSE( RANDBETWEEN( 1, 4 ), "u12345", "u0876234", "u567891", "u0987121" )


REMOVESPACES


You can remove spaces from the field in a placeholder with the function:  REMOVESPACES()


SUBSTITUTE


You can use this function to remove spaces of other characters or to replace some characters


E.g. SUBSTITUTE (client.vatnumber, " ", "")


DATEFORMAT


This function can be used to format dates to display in a specific way.


E.g. Payment is due {DATEFORMAT( job.paymentdate, "DD/MM/YYYY")}


This function replaces the existing date formatting option for placeholders, as DATEFORMAT can be combined with other functions.


E.g. {DEFAULT(DATEFORMAT(job.vatpaymentdate,"DD/MM/YYYY"),"n/a")}


The date formatting needs to be in quotes when used with the DATEFORMAT function.


Additional function options:


Calculate days remaining until a date


You can use this function to calculate days remaining until a certain date, or a number of days between 2 dates:  


{DATEDIF(client.date1,client.date2)}

{DATEDIF(today(),client.date1)}

{DATEDIF(client.date1,job.pivotaldate)}


You can use this within an IF function, to check for whether either of the date sources exists or not:


IF(AND(client.date1,client.date2),DATEDIF(client.date1,client.date2)) 


Support for logical functions AND() and OR() and NOT()


This function allows you to add extra conditions to an IF function, for example:


IF( AND(client.fees > 1000, client.grade = "A"), "Yay", "Boo")


Test for secondary contacts in placeholders


You can now test for whether a secondary contact exists before pulling their information into a placeholder, using the IF function:


{IF (client.contact2, "Contact 2 exists", "Contact 2 does not exist)}


Also:


Dear {client.contact1.firstname} {IF(client.contact2)} and {client.contact2.firstname} {ENDIF} {IF(client.contact3)} and {client.contact3.firstname}{ENDIF}


Computed fields


Form fields can now be computed from an expression e.g. the field "Annual fees" could be automatically calculated via:


IF(client.paymentmethod = "Monthly", client.fees*12, client.fees )



Service scope in placeholders


A new scope for clients to use in placeholders to do things if services are selected. 


For example:


{IF (services.s12345678, "You are on our Tax Return service", "You are currently not on our Tax Return service")}


You can find the service name by looking in the url for the service template.