Execute JavaScript in Desktop flow using Microsoft Power Automate

Microsoft Power Automate is a software by Microsoft for the automation of recurring tasks. It is part of the Microsoft Power Platform line of products together with products such as Power Apps and Power BI. More Details https://powerautomate.microsoft.com/en-us/

Desktop flows are the existing robotic process automation (RPA) capabilities in Power Automate and enable to automate of all repetitive desktop processes.

Scripting actions enable you to run blocks of code and implement custom behavior in your desktop flows. All scripting actions follow the basic structure of the respective programming or scripting language: PowerShell, Python, DOS Command, VBScript, and JavaScript.

Executes some custom JavaScript code and retrieves its output into a variable.

In scripts, use the var notation to declare new variables and the WScript.Echo function to return values from Run JavaScript actions.

Execute the JavaScript scripts, and use the var notation to declare new variables and the WScript.Echo function to return values from Run JavaScript action.

Reading this article, you can learn how to Execute the JavaScript scripts using Run JavaScript actions with the Desktop flow in Microsoft Power Automate.

The following important tools are required for developing Microsoft Power Automate,

  1. Windows 10/11 (Recommended)
  2. Power Automate Desktop - Download the Power Automate installer

Now we can discuss step-by-step App development.

Step 1. Open Microsoft Power Automate ->  New Flow

Next, Give the Flow name as PADJavaScript, Click the Create button,

Execute Java Script in Desktop flow using Microsoft Power Automate

After that, we can see the Desktop flow,                                                                                

Execute Java Script in Desktop flow using Microsoft Power Automate

Step 2. For Testing, Run JavaScript action in Scripting actions,

Add the Run JavaScript action, and Set the JavaScript to run parameter as.

var variableName = "Welcome to C# Corner";
WScript.Echo(variableName);

Click Save Button

Execute Java Script in Desktop flow using Microsoft Power Automate

And the following variables are produced automatically, For the script's output JavascriptOutput variable and enable the ScriptError variable for errors that may occur during the execution of the Javascript code.

Execute Java Script in Desktop flow using Microsoft Power Automate

For Displaying the Java Script Output, Add the Display message action, Set the Message box title Parameter value as "DispJSOutput", and Message to display Parameter value as,

  • %JavascriptOutput%
  • %ScriptError%

and Click the Save Button

Execute Java Script in Desktop flow using Microsoft Power Automate

Now, Save the PADJavaScript Desktop Flow,

Execute Java Script in Desktop flow using Microsoft Power Automate

Step 3. Now we can run your PADJavaScript Desktop Flow in Microsoft Power Automate, 

The output of the PADJavaScript,

Execute Java Script in Desktop flow using Microsoft Power Automate

Summary

You have successfully tested the Run JavaScript action in Desktop flow – PADJavaScript in Microsoft Power Automate. 


Similar Articles