Run JavaScript Code
Description
This action allows you to write and run JavaScript code directly inside your flow. It executes the code and returns the result of the return statement.
Input Arguments
Input Argument | Type | Description | Required? | Advanced Option? | Default |
---|---|---|---|---|---|
JavaScript Code | String (Code) | Enter your JavaScript code as a text block. The code should include a return statement, which specifies the value the action will output. | ✔️ | ❌ | - |
Output
Response | Type | Description |
---|---|---|
Value returned by the JavaScript code’s return statement | Any valid JavaScript type (e.g., string, number, boolean, array, object) | The result of the executed JavaScript code, as specified by the return statement. |
Power Automate Examples
Calculate Total Price Including Tax
This JavaScript code calculates the total price including tax.
First, it sets the variable price to 19.99. Then, it calculates the tax as 20% of the price (price * 0.2). Finally, it returns the sum of the price and the tax.
Looking for the response to this example? Scroll up to see the Output tab.
Check Pass or Fail Based on Score
This JavaScript code checks if a score is passing or failing.
The variable score is set to 85. It uses an if statement to check if the score is 80 or higher. If the score is 80 or above, it returns "Passed". Otherwise, it returns "Failed".
Looking for the response to this example? Scroll up to see the Output tab.