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:PopularNumber Functions
Format number Format a number with grouped thousands and optionally decimal digits. Round Round the float number based on the precision from the second parameter. Ceil Rounds to the nearest integer up. E.g. 2.1 =3.Some 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. Max Returns maximum value of list of elements or separate field values. or Min Returns minimum value of list of elements or separate field values. orPopularDate functions
Date Format date value. Examples of the function "Date": Display current time Specify timezone Specify output format Specify output and input format Datetime Format datetime value. NB! You need to use the Date forSome readersUtility functions
Empty The empty(value) checks if the variable exists and if the value is not “falsy”. Returns true if var does not exist or has a value that is empty or equal to zero, aka falsely. Otherwise, it returns false. What qualifies as "falsy"? Anything that returns false if cast to boolean Empty array Zero as number Zero as string Empty string null false undefined JSON decode Decode JSON string to usSome readers