Execute javascript

NO IMAGE

 Home > User guide > How to use the BOT editor > Execute Javascript

Execute javascript

Add a task to execute javascript

Cloud BOT can execute arbitrary Javascript in the automatic operation procedure.

  • By clicking the "Script" button in the task, the javascript input window will open.
  • Enter any javascript and press the OK button, and the task to execute the entered javascript will be added.

About javascript description and specifications

he value stored as data in BOT can be referenced by using $ {data name}.

You can browse the data and insert it into the Script from the Data reference button.

Store javascript execution result in data

By selecting the storage destination data, the execution result of javascript can be stored in the data.

* The result of the last executed process in javascript is stored in the storage destination data.

  1. Select "New data" from the pull-down menu of the storage destination data.
  2. Select the type of data by selecting new data.
  3. Select the data type from the type pull-down. (*)
  4. Enter the data name and press OK.

* When storing data, you can select the storage destination data from "Text" or "Multiple text".

Cast rule

When storing Javascript values in the data, the values are cast according to the cast rules.

Javascript value Destination storage data type Cast result
123 Text 123
[1,2,3] Text 1,2,3
"123" Text 123
["1","2","3"] Text 1,2,3
["1","2","3"] Multiple text 1,2,3

Javascript utilization sample

Operation detailsscript sample
Click a buttondocument.querySelector("#selector").click()
Enter in the input formdocument.querySelector("#selector").value = ${value};
Delete unnecessary characters
(080-1234-5678 → 08012345678)
var text = ${value};
text = text.replace( '-' , '' );
Use a regular expression to remove in a pattern
(2021/11/26 15:13 → 2021/11/26)
var text = ${value};
text = text.replace( /\s\d{2}:\d{2}/ , '' );
Use regular expressions to replace all characters
(2021/11/26 → 2021-11-26)
var text = ${value};
text = text.replace( /\//g , '-' );
Change the format using a regular expression
(2021-11-26 → 26th November 2021)
var text = ${value};
text = text.replace( /(\d{4})-(\d{2})-(\d{2})/ , '$1yeas$2month$3date');
Get the day beforevar date = new Date();
date.setDate(date.getDate() - 1);
date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate();