Using Lodash in Unqork
Overview
Put simply, Lodash Lodash is a JavaScript library that lets you perform functions for common programming tasks. is a Javascript JavaScript is an object-oriented computer programming language. It is most-commonly used for interactive effects in the browser. library of functions. You can use these functions to complete common tasks in Unqork. You'll write Lodash as a formula with parameters relative to the function you decide to use. For example, _.set is a Lodash function that accepts three parameters to set a new object value.
Where to Use Lodash in Unqork
Unqork lets you use Lodash anywhere you write formulas. For example, you can use Lodash in a Calculator component or Decisions component. You can also use Lodash in any of the formula operators in a Data Workflow.
Let's say you want to use a Calculator component to set key/value pairs in an object. You can use the _.set Lodash function from earlier to set the value and path of your object. To do this, you'll write the function as an output formula in your Calculator component.
Writing Lodash Functions
Before you write your Lodash function, determine which function to use by visiting the function library documentation here: https://lodash.com/docs/4.17.15.
Writing Lodash in Unqork differs from how you write it elsewhere. Typically, Lodash functions start with a _. followed by the function name and its parameters. In Unqork, you'll write Lodash formulas as follows: =LODASH("method", parameter 1, parameter 2).
Here's a breakdown of each part of the formula:
Part of Formula | Description |
---|---|
=LODASH |
Tells Unqork you're using a Lodash-type function. |
"method" |
Declares which Lodash function you're using. You must write your functions in camelCase Includes the Short Answer component, Long Answer component, Select Boxes, Radio component, Dropdown, Number component and Single Checkbox. between double-quotes. When copying and pasting double-quotes, confirm they are not stylized. Adding stylized double-quotes might result in an error. |
parameter 1, parameter 2 |
Declares the parameters of the function you're using. You must write these parameters in the same order as the Lodash documentation referenced above. If your parameter uses a hard-coded value, you'll enter it between double-quotes. If your parameter references a variable, quotes are not necessary. |
Apply your formula to a Lodash function. Let's return to the example from earlier for setting key/value pairs in an object. Looking at the Lodash library, it's written as _.set(object, path, value). In your Unqork formula, you'll modify the formula as =LODASH("set", object, path, value).
Resources