You can run JavaScript code directly within a CustomJS action in your Microsoft Power Automate flow. If you want to manage and write complex JavaScript functions.

The customJS action consists of four fields: Connection, Input, JavaScript code and Return Type.
| Field | Description | How to use it |
|---|---|---|
| Connection | Links the action to the CustomJS service, enabling JavaScript execution. | Select or create a connection (e.g., Coding Service). Usually set up once and reused across flows. |
| Input | Data passed into the JavaScript code, available as the input object. | Enter plain text, arrays, or valid JSON strings. For Power Automate arrays, you may need to convert them to JSON first. |
| JavaScript Code | The script that will be executed by CustomJS. Must follow JavaScript syntax. | Ensure the code ends with a return statement so data is passed back to Power Automate. |
Inputs are accessed through the input object. For complex scenarios, you can:

When using asynchronous code (like fetch, database calls, or API requests), await the result and then return it. If you forget await or don’t return the resolved value, Power Automate will just get a pending Promise, not usable data.
| Without await | With await | |
|---|---|---|
| Code | // Incorrect: returns a Promise, not data
return fetch(input.url).then(res => res.json());
| // Correct: resolve the Promise before returning
const response = await fetch(input.url);
const data = await response.json();
|
| Result | Power Automate receives a Promise instead of usable data. The next action cannot work with unresolved Promises. | Power Automate receives the actual data (JSON object with status and content). The next action can directly use this result. |
Inline comments usually work if you place them correctly with line breaks. However, misplaced comments can prevent the code from running as expected. Consider removing them if you have issues.
| Inline comments | Without inline comments | |
|---|---|---|
| With inline comments | // return full name
return input.firstName + " " + input.lastName;
|
return input.firstName + " " + input.lastName;
|
| Result | Power Automate may not receive the intended output if the comment interrupts code execution. | Comments cannot interrupt code execution. |