What is Expression Language?
Expression language in PDF Generator API is a specific programming language that allows writing mathematical and logical expression to manipulate the value displayed by component. Expression language can be written into the "Text" component "Raw value" under the "Formatting" view. Example expression % 2 + dataFieldName + dataFieldName2 *0.5 %PopularSupported operators
Arithmetic Operators + (Addition) % 2 + 3 % >5 - (Subtraction) % 7 – 4 % >3 * (Multiplication) % 2 * 3 % >6 / (Division) % 9 / 3 % >3 % (Modulus) % 10 % 3 % >1 (Pow) % 5 2 % >25 Logical Operators ! (not) % !true ? "true": "false" % >false && (And) % true && false ? "true": "false" % >false (Or)PopularFunctions
Number functions The Text component must have the Format set to Number. Format number Format a number with grouped thousands and optionally decimal digits. % numberformat( float number , decimalplaces , decimalseparator , thousandsseparator ) % Round Round the float number based on the precision from the second parameter. % round( float number , integer precision ) % Ceil Rounds to the nearest integer up. E.g. 2.1 =3.PopularCommon use-cases of the Expression language
Using filter and iterate function Let's say you have an array of line items, where items can be of different type (e.g. "Food", "Drinks", etc...) and you need to get a SUM of a specific type. Then you can do it using a combination of filter and iterate function: % sum(iterate(filter( lineitems , 'type == "Drinks"'),'totalprice')) % Example JSON dataset:Some readersNumber Functions
Format number Format a number with grouped thousands and optionally decimal digits. % numberformat( float number , decimalplaces , decimalseparator , thousandsseparator ) % Round Round the float number based on the precision from the second parameter. % round( float number , integer precision ) % Ceil Rounds to the nearest integer up. E.g. 2.1 =3.Few readersString functions
Uppercase To display data field value in uppercase, use following expression. % uppercase( dataFieldName ) % Lowercase To display data field value in lowercase, use following expression. % lowercase( dataFieldName ) % Capitalize Uppercase the first character of each word in a string. % capitalize( dataFieldName ) % Split The split(delimiter, string) function allows to split string into an array.Some readersList (array) functions
Count It is possible to count number of items in list. % count( lineitems ) 3 ? 'More than three' : 'Less than three' % Max Returns maximum value of list of elements or separate field values. % max( lineitems::quantity ) % or % max( dataField1 , dataField2 , ..., dataFieldN ) % Min Returns minimum value of list of elements or separate field values.Some readersDate functions
Date Format date value. NB! You need to use the Date formatter. % date( dateString , timezone , addDays , outputFormat , inputFormat ) % Examples of the function "Date": Display current time % date('now') % Specify timezone % date( dateValue , 'UTC') % Specify output format % date( dateValue , 'UTC', 0, 'd/m/Y') % Specify output and input format % date( dateValue , 'UTC', 0, 'd/m/Y', 'm/d/Y') % (https://storage.crisp.chat/users/helpFew readersUtility functions
Empty The empty(value) function checks if field has value. % empty( dataField ) ? 'No value' : 'Field has value' % JSON decode Decode JSON string to use in an expression. % jsondecode(' "key": "value" ', true) %Some readers