knowledgecenter-breadcrum

Knowledge Center

31 Mar, 2026

Debugging Power Pages Server Logic Using Visual Studio Code

Posted on 31 Mar, 2026 by Trupti Nikumbh, Posted in Microsoft Power Platform PowerApps Portal Power Platform

Blogs

Power Pages Server Logic allows developers to execute secure backend JavaScript directly within Power Pages. It is commonly used for tasks like calling external APIs, validating business rules, or performing secure data processing.

Microsoft recently introduced the ability to debug server logic locally using Visual Studio Code, which makes development faster and easier.

In this blog, we will walk through a complete step-by-step process to:

  • Create Server Logic in Power Pages

  • Download the portal code

  • Open the project in Visual Studio Code

  • Add breakpoints

  • Debug the server logic

 

Scenario Used in This Blog

In this example, our Server Logic will call an external API and retrieve user data.

We will use a public API:

 https://jsonplaceholder.typicode.com/users

This API returns sample user data, which makes it ideal for debugging demonstrations.

 

Step 1: Create Server Logic in Power Pages

First, create the server logic inside your Power Pages site.

Steps

  1. Open Power Pages Studio

  2. Navigate to Set up workspace

  3. Click Server Logic

  4. Click + New Server Logic

Provide the following details:

Field Value
Name Service
Display Name Service (optional)
Web Role Authenticated Users

Save the server logic.
Note: Add Web Role as per your requirement

 

Step 2: Add Server Logic Code

Click Edit Code and add the following code.

const baseUrl = "https://jsonplaceholder.typicode.com";

async function get() {

try {

Server.Logger.Log("Calling external API");

const response = await Server.Connector.HttpClient.GetAsync(
`${baseUrl}/users`,
{"Accept":"application/json"}
);

const users = JSON.parse(response.Body);

return JSON.stringify({
totalUsers: users.length,
users: users
});

} catch (err) {

Server.Logger.Error(err.message);

return JSON.stringify({
error: err.message
});

}

}

This server logic:

  1. Calls an external API

  2. Retrieves user data

  3. Returns the data as JSON

 

Step 3: Install Required Tools

Install Power Platform Tools Extension

Open VS Code → Extensions and install:

 Power Platform Tools

 

Step 4: Authenticate to Power Platform

Open the terminal and run:

pac auth create

Sign in with your Power Platform account.

 

Step 5: Download the Power Pages Site

Create a folder where the portal code will be downloaded.

Example:

PowerPagesProjects

Run the following command: 
pac org list
pac org select --environment

pac paportal download --path . --webSiteId -mv Enhanced
 

Once the download completes, your project structure will look like:

powerpages-site
│
├── web-pages
├── web-files
├── web-templates
├── site-settings
└── server-logic

Your server logic file will be located here:

 server-logic
└── Service.js

 

Step 6: Open the Project in Visual Studio Code

Open the downloaded folder in Visual Studio Code.

Navigate to:

server-logic

Open the file:

Service.js

 

Step 7: Enable Debugging

Paste the method name that you want to start debugging at the end of the server logic file.

Example: get();

This tells VS Code which function to execute during debugging.

 

Step 8: Add Breakpoints

Breakpoints pause code execution so you can inspect variables.

Add breakpoints at these lines.

Breakpoint 1 – Start Execution

Server.Logger.Log("Calling external API");

Purpose:
Verify that the server logic execution begins.

 

Breakpoint 2 – API Call

const response = await Server.Connector.HttpClient.GetAsync(...)

Inspect:

response.StatusCode
response.Body

Expected output:

StatusCode: 200
Body: JSON response

 

Breakpoint 3 – Parse API Response

const users = JSON.parse(response.Body);

Inspect:

users
users[0]

Example:

{
id: 1,
name: "Leanne Graham",
email: "Sincere@april.biz"
}

 

Step 9: Start Debugging

Press:

F5

Visual Studio Code will start the debugger.
Click on Debug Current file.

The execution will pause at the breakpoints you created, allowing you to inspect variables and step through the code.

 

Understanding the Debugging Environment

Power Pages debugging uses a mock runtime environment

  • This means:

    • Server objects like Dataverse, Context, and User are simulated

    • External API calls using HttpClient work normally

Because of this, local debugging is mainly used to verify:

  • Logic flow

  • API integration

  • Code structure

Limitations of Local Debugging

Keep the following limitations in mind:

  • Local debugging does not connect to the live Power Pages runtime

  • Debugging works only in Visual Studio Code Desktop

  • Many server objects are mocked (simulated)

  • Results may differ from production behavior

  • Always test server logic in a development or test environment before production

Conclusion

Debugging Power Pages Server Logic locally with Visual Studio Code significantly improves the development experience. Developers can inspect variables, test API integrations, and validate logic without repeatedly deploying code to the portal.

Comment

This is a Required Field

Loading

Recent Updates

Blogs
31 Mar, 2026

Create and Deploy a Single Page Application (SPA) in Power Pages

In this blog, we’ll build and deploy a Single Page Application (SPA) using React + Vite and host it on…

READ MORE
BuildAndDeployPCF_Thumbnail.png
Blogs
25 Mar, 2026

Build And Deploy Your First Dataset PCF Control In Dynamics 365

Introduction In Dynamics 365, subgrids are commonly used to display related records, such as Opportunities under an Account. While out-of-the-box…

READ MORE
How to Add a Custom Button in the Global Command Bar in Dynamics 365
Blogs
17 Mar, 2026

How to Add a Custom Button in the Global Command Bar in Dynamics 365

Introduction: Global Command Bar in Dynamics 365 (also known as the Global Tab or Mscrm.GlobalTab) is the top-level ribbon that stays visible…

READ MORE