Articles in this section

Create or explain JavaScript using Celigo AI component

For users with minimal programming experience, Celigo AI simplifies the process of writing JavaScript code and establishing workflows, by generating explanations for various sections of the JavaScript code. Define the use case in a plain English prompt, and Celigo AI will generate the JavaScript code without requiring the user to manually write the syntax in the editor. You can use multiple prompts for complex use cases.

Prerequisite: Celigo AI {https://theme.zdassets.com/theme_assets/1098969/ede006d404609cd6f0d367f55725b8a1022543b9.svg}Celigo AI must be enabled in your integrator.io account. Click the avatar icon in the upper right corner of integrator.io and click Profile.

Note

An error displays if your Celigo AI prompt is empty or invalid.

Create JavaScript code using simple language prompts

After the results of your initial prompt are retrieved, you can enter additional prompts that describe additional changes to the expression that Celigo AI might not have fully understood. All previously provided prompts will be saved and can be viewed or copied until you click Reset conversation or close the editor window. The editor also provides sample text that will inform your use of the text prompt field.

Click thumbs up or thumbs down for each prompt to indicate if the response provided by Celigo AI was helpful or unhelpful.

Example 1: A simple expression to check if the ID is even

Sample JSON

Prompt

JavaScript Code

Output after Auto preview

Function: Filter

{

"record": {

"id": 123,

"name": "Bob",

"age": 33

}

}

id should be even

function Filter(options) {

var record = options.record;

var id = record.id;

if (id % 2 === 0) {

return true;

} else {

return false;

}

}

false

22086368028827-fd2d5167-68eb-445f-9859-d60bd4c6ec72

Example 2: A series of expressions to validate the JSON

Sample JSON

Prompt

JavaScript Code

Output after Auto preview

Function: Filter

{

"record": {

"id": 123,

"name": "Bob",

"age": 33,

"payment_date": "10/06/2023"

}

}

id should be even

function Filter(options) {

const { record } = options;

const { id } = record;

return id % 2 !== 0;

}

true

can you add one more condition that name should be Bob

function Filter(options) {

const { record } = options;

const { id, name } = record;

return id % 2 !== 0 && name === 'Bob';

}

true

add one more condition that payment_date should be not older then 90 days

function Filter(options) {

const { record } = options;

const { id, name, payment_date } = record;

const currentDate = new Date();

const paymentDate = new Date(payment_date);

const daysDifference = Math.floor((currentDate - paymentDate) / (1000 * 60 * 60 * 24));

return id % 2 !== 0 && name === 'Bob' && daysDifference <= 90;

}

true

22086335938331-27cdd957-6374-4a91-b566-5fc8bf639828

Explain JavaScript code from syntax to simple language

Celigo AI explains the JavaScript code for full or partial selection. Select the part of the code that you want Celigo AI to explain, and click Explain selection. Celigo AI will generate an explanation for the selected code. The selected lines remain highlighted until you close the explanation window. You can reposition the explanation window as needed.

Example 1: Explanation for a simple expression

Sample JSON

Prompt

JavaScript Code

Explain selection

{

"record": {

"id": 123,

"name": "Bob",

"age": 33

}

}

id should be even

function Filter(options) {

var record = options.record;

var id = record.id;

if (id % 2 === 0) {

return true;

} else {

return false;

}

}

The `Filter` function takes an `options` object as a parameter and returns a boolean value.

1. The `id` property of the `options.record` object is assigned to a variable called `id`.

2. The function checks if the `id` is divisible by 2. If the `id` is divisible by 2 with no remainder, the function returns `true`. Otherwise, it returns `false`.

The function can be used to filter out records with odd `id` values.

22086335939867-8ef8342d-2f83-452c-8d61-ab960eaa7a3f

Example 2: Explanation for a series of prompts

Sample JSON

Prompt

JavaScript Code

Explain selection

{

"record": {

"id": 123,

"name": "Bob",

"age": 33,

"payment_date": "10/06/2023"

}

}

id should be odd

function Filter(options) {

const { record } = options;

const { id } = record;

return id % 2 !== 0;

}

The `Filter` function takes an `options` object as a parameter and returns a boolean value.

1. The `record` property of the `options` object is destructured and assigned to a constant variable called `record`.

2. The `id`, `name`, and `payment_date` properties of the `record` object are destructured and assigned to separate constant variables.

3. The current date is obtained by creating a new `Date` object and assigned to a constant variable called `currentDate`.

4. The `payment_date` is converted to a `Date` object and assigned to a constant variable called `paymentDate`.

5. The difference in days between the `currentDate` and `paymentDate` is calculated using the formula `(currentDate - paymentDate) / (1000 * 60 * 60 * 24)`. The result is rounded down to the nearest whole number using `Math.floor()` and assigned to a constant variable called `daysDifference`.

6. The function returns `true` if the following conditions are met:

- The `id` is not divisible by 2 with no remainder (`id % 2 !== 0`).

- The `name` is equal to 'Bob'.

- The `daysDifference` is less than or equal to 90.

If any of these conditions are not met, the function returns `false`.

The function can be used to filter out records that have an odd `id`, a name other than 'Bob', or a payment date that is more than 90 days ago.

can you add one more condition that name should be Bob

function Filter(options) {

const { record } = options;

const { id, name } = record;

return id % 2 !== 0 && name === 'Bob';

}

add one more condition that payment_date should be not older than 90 days

function Filter(options) {

const { record } = options;

const { id, name, payment_date } = record;

const currentDate = new Date();

const paymentDate = new Date(payment_date);

const daysDifference = Math.floor((currentDate - paymentDate) / (1000 * 60 * 60 * 24));

return id % 2 !== 0 && name === 'Bob' && daysDifference <= 90;

}

22086368031771-5c0faf4c-f67c-4cff-95af-21b53135a5e0

Example: Partial selection

When you select the syntax partially and click Explain selection

22086368035099-17db0512-40ea-4380-bc8a-c4b7bb118d7f
Was this article helpful?
0 out of 0 found this helpful

Comments

0 comments

Please sign in to leave a comment.