Expressions - cheatsheet
Jigx wants to help you build solutions quickly and easily. To help you do this, here is a list of functionality or data results you might want to use in your app with the expression used to achieve it. This is a starting point; you can adapt or add to the expression as needed to get the expected data results when building solutions. Refer to the Expressions section in the Examples tab for working examples and code snippets for various JSONata expressions.
Create Filters on a list (Path Operator expression)
=$filter(@ctx.datasources.filter-list, function($v){$contains($string($v.status), $string(@ctx.components.filter-list.state.filter != null ? @ctx.components.filter-list.state.filter:'')) })[]OData filter generation
=($map(@ctx.datasources.employee-customer-detail-string, function($v) { "CustomerID eq " & $v.AccountID}) ~> $join(" or "))Create Search for a list (Path Operator expression)
=$filter(@ctx.datasources.dmsrole-nonlife, function($v){ @ctx.datasources.dmsrole-nonlife ? $contains($string($v.DMSRole),$string(@ctx.components.RosterPositionID.state.searchText != null ? @ctx.components.RosterPositionID.state.searchText:'')) :true})[]Create a placeholder (Boolean expression)
See tips and tricks when using placeholders for additional information.
placeholders:
- when: =$count(@ctx.datasources.employees-dynamic) > 0 ? false :true
title: There is no data
icon: missing-dataCheck if a field's value is Null (Boolean expression)
[email protected] != null ? true: false=$type(@ctx.current.item.EngineStop) = 'null' ? true: false=$count(@ctx.datasources.data.id) = 0 true:falseEvaluate
PathsData (String Function expression)
=$eval(@ctx.current.item.pathsData)Use evaluate to change data text to JSON object
=$eval(@ctx.datasources.weatherData.temperatures_max)Base64 image (String expression)
="data:image/png;base64," & @ctx.datasources.mydata.dataString to number (String expression)
=($number(@ctx.datasources.tmra-graph.Total) >= 5)=($number(@ctx.datasources.tmra-graph.Total) < 8) ? true : falseNumber to string (String expression)
=$string(@ctx.current.item.ID)Combining first and last name (Concatenate)
=(@ctx.current.item.firstName & ' ' & @ctx.current.item.lastName)Splitting display name into first and last name (String expression)
=$substring($substringBefore(@ctx.inputs.info.FromUserDisplayName, ' '), 0, 1)Displaying text
Show text and split name and surname and only displaying name (String expression)
='Hello, ' & $substringBefore(@ctx.user.displayName, ' ')Show text followed by user's display name
="Welcome " & @ctx.user.displayNameTwo letter placeholder for avatar (String expression)
=$uppercase($substring($substringBefore(@ctx.current.item.firstName, " "), 0, 1) & $substring($substringAfter(@ctx.current.item.lastName, " ") , 0, 1) )True or False ? (Boolean expression)
=$boolean(@ctx.datasources.tmra.TwoPilots) ? true : falseAdding an expression into a string
('Hello, my name is ' & @ctx.user.displayname)
('Day ' & @ctx.datasource.mydata.date & ' agenda')
"Day one agenda"Working with Date and Time expressions
Convert UTC to milliseconds
=$toMillis()Convert millisecond to UTC
=$fromMillis()Transform any date to new format
=$fromMillis($toMillis(@ctx.inputs.info.EndDate), '[M01]/[D01]/[Y0001]', @ctx.system.timezone.offset)Add days to date + convert to local timezone + format
=$fromMillis($toMillis(@ctx.datasources.mission-list-global.CrewNotified) + 86400000,'[Y0001]-[M01]-[D01]T[H01]:[m01]:[s01].[s001]Z',@ctx.system.timezone.offset)Set date and time in datePicker to local timezone + format
=$fromMillis($toMillis(@ctx.components.datePicker.state.value), '[M01]/[D01]/[Y0001] [H01]:[m01]:[s01]', $string(@ctx.system.timezone.offset))Add days from current date and add additional time from current time
=$fromMillis($toMillis($now()) + 5 * 60 * 60000 + @ctx.current.item.eventEnd * 3600000)System variables
Get currently logged in user (Jigx system expression)
Results can include id, email, name.
Is the mobile device offline (Jigx system expression)
[email protected] = trueGet country flag icons using system (Jigx system expression)
Create a unique GUID
=$uuid()Formatting Numbers (Numeric functions)
=$formatNumber(@ctx.inputs.info.TotalSQft, '#,###')Using objects in expressions
Sorting an array of objects using a lambda (embedded) function
This example with data and the result can be viewed in JSONata exerciser.
$sort($.{"id": id,"amount":amount,"name":name}, function($l, $r) { $l.amount > $r.amount})Setting up complex objects with an embedded array
This example with data and the result can be viewed in JSONata exerciser.
$.{"message": {"subject": subject,"body": {"contentType": "Text","content":
messageBody},"toRecipients": toAddresses#$i.{"emailAddress":
{"address":$}}[]}}Create a basic join on a static datasource to a local datasource
[email protected]@$p.$merge([$p, @ctx.datasources.localdatabase[id = $p.id]]Transform longitude and latitude data to show markers on a location component
markers:
data: |
[email protected].{"lng": $number($.lng), "lat": $number($.lat)}Working with values
Find the value relative to the current node so all paths are relative to it
=$.path.to.valueFind the value relative the root node of the supplied context, no matter what is the current node
Jigx converts @ctx. to $$. when executing expressions in jsonata
=$$.path.to.valueUse the JSONata built-in index parameter combined with a filter
[email protected]#$i.answer[$i=3]Update multiple records in execute-entities (operators > transform)
To update multiple records using the Execute-entities action, you can use the expression below.
data: =ctx.datasources.customers ~> | $ | { "customerType": "Bronze "} | Validate text fields using JSONata + Regex expression
See the examples provided in Regex expressions.
Use JavaScript functions in expressions
See more examples provided in JavaScript expressions.
# Calculate loan repayment expression cofigured in a jig
value: =$jsfunctions.formatCurrency($jsfunctions.calculateLoanPayment(@ctx.components.principal.state.value, @ctx.components.annualRatePercent.state.value, @ctx.components.loanDuration.state.value),'$')/* JS function is added under scripts/expressions folder
*/
export function formatCurrency(amount, currencySymbol) {
return currencySymbol + parseFloat(amount).toFixed(2).replace(/\d(?=(\d{3})+\.)/g, '$&,');
}JavaScript checking any value for false
Checks for undefined, false, empty string, empty objects, null, empty array, and boolean false. It is better than using (jsonataTruthy) or $empty or $exist in JSONata as it checks for all scenarios and returns false in a single function, whereas using a combination of JSONata functions is necessary to return false.
export function juthy(input) {
if (
input === undefined ||
input === false ||
input === '' ||
(typeof input === 'object' && input !== null && Object.keys(input).length === 0) ||
input === null ||
(Array.isArray(input) && input.length === 0)
) {
return false
}
return true
}Last updated
Was this helpful?