Server Logic in Practice: The Good, the Bad, the Ugly

IMPORTANT
Help UKRAINE ! Your action matters! Donate to support Ukrainian Army! Donate to charity funds! Organize/join street protests in your city to support Ukraine and condemn Russian aggression! Expose and report Russian disinformation! #StandWithUkraine

Server Logic went GA back in April 2026. I was excited about it and even called it the new default backend in my Power Pages Backend Trifecta post. Unfortunately, with projects lined up, I didn’t have a chance to properly dive deep into Server Logic beyond occasional testing. Recently that changed. After using it on real projects, I still think it’s the new default, but I also found where the docs and tooling haven’t caught up yet. And boy, oh boy, do I have a lot of things to share.

This post starts the Server Logic in Practice series, where I share what it is actually like to use Server Logic in production. As the title suggests, this one covers the good, the bad, and the ugly parts.

Quick introduction

If you have never written Server Logic, start with Microsoft’s Server logic overview and Author server logic.

In short: a Server Logic record is just a JavaScript file with one function per HTTP method (get, post, put, patch and del, because delete is a restricted keyword). The site exposes it at /_api/serverlogics/<name> to the web roles you assign, and the code runs on the server on behalf of the signed-in user, with their table permissions applied.

The Good

Let’s start with the good parts.

First and foremost, the ability to create custom business logic and execute it securely is great. No longer do we need to hijack plugins, do tricky page-as-API approaches via Liquid, or reach for the Companion App pattern (an external API endpoint, like an Azure Function) for complex operations. It’s a clear and direct path that works across both traditional and SPA sites, with simple configuration.

Security is built in. Table permissions and web roles of the current user are applied automatically to every request, and on top of that you restrict each endpoint to specific web roles when you configure it. You don’t even need the Webapi/<table>/enabled site setting: Server Logic reads the table through its permissions alone, while the browser’s /_api/<table> gets a 404 ResourceDoesNotExists. As far as the browser can tell, the table doesn’t exist, and your endpoint becomes the only door to it.

Server objects give you everything else: Dataverse for data, HttpClient for external systems, User for the signed-in contact, plus SiteSetting, EnvironmentVariable, Website and Logger. That’s enough to build complex business logic and call it from the site.

There is even a local debugger in Visual Studio Code. It runs your code in plain Node.js with a mocked Server object, so it’s great for checking logic flow and real HttpClient calls. It tells you nothing about permissions, Dataverse responses or the sandbox rules, though, and some mocked names differ from the real ones, so expect to adjust the generated mock file before your code runs.

With all of that, you have all the things that you need. Right?

The Bad and the Ugly

Time to put the rose-tinted glasses away and look at Server Logic in a real-world scenario. I’ve ordered these from the ones you notice on day one to the ones you only hit on a real project.

Pure JavaScript, and not all of it

The first thing you notice is that Server Logic only allows pure JavaScript. No npm, JSR or any other package registry. It makes sense from a security perspective (hello to all the npm security issues from this year), but it makes complex business logic harder to write, especially when integrating with third-party systems.

We might get native support for Power Platform connectors (the ones cloud flows use) in the future, which would solve a lot of that problem. But I can only assess the system as it is, without awarding points for potential future updates.

The sandbox is also stricter than the docs say. Learn lists the restricted patterns (eval, require, setTimeout and so on), but function expressions are rejected too. The endpoint just returns a generic 400:

js
// Rejected: the function keyword used as an expression
const double = function (x) { return x * 2; };
items.map(function (x) { return x * 2; });

// Works: arrow functions and named function declarations
const double = (x) => x * 2;
function double(x) { return x * 2; }
items.map((x) => x * 2);

So stick to arrow functions and named declarations. And since the local debugger is plain Node.js, it won’t warn you about any of this.

Endpoint names that break pac pages download

In big projects, keeping things organized is important. After downloading, all Server Logic ends up in a single server-logic folder, two files per endpoint, and in a big project that gets noisy. Since the endpoint name is used for the file names, the first thing I tested was whether a subpath, like payment/get-details, would give me subfolders.

The name was valid; the endpoint was working, over HTTP and from Liquid.

Until I tried to download the site. pac pages download failed for the whole site with “Could not find a part of the path”. Uploading works, and creates the record with a subpath name just fine. So one developer can push it from source control, and from then on nobody can pull the site.

So use flat names: payment-get-details, not payment/get-details.

Debugging on the live website

The local debugger is useful, but a lot of the time things that work locally fail on the actual site, and you can’t mock it all. So when I saw that Microsoft supports live debugging via an official browser extension and the Logger server object, I was quite optimistic. Then I tried to use it to troubleshoot a failing endpoint.

The Microsoft Power Pages extension for Edge DevTools installed successfully. The User/Debug site setting was configured. Server.Logger.Error was in place to capture the actual error. The endpoint failed, and the extension showed nothing.

Judging by its 2.6 out of 5 rating, I’m not the only one who struggled with it. I hope it gets more reliable, because live debugging is exactly what Server Logic needs, and not having it makes troubleshooting much harder.

Until then, the good old “return the error and show it” approach works. Just be careful with it in production: whatever you return goes straight to the browser. And, as the next section shows, a returned error doesn’t look like an error at all.

The response envelope is different

“Author server logic” documents the response envelope in PascalCase: RequestId, Success, Data, ExecutionTime, Error. Here’s what the server actually sends:

json
{
  "requestId": "6a5af999-…",
  "success": true,
  "data": "{\"ok\":true,\"data\":{\"lines\":[…],\"itemCount\":2,\"total\":548}}",
  "serverLogicName": "checkout"
}

Everything is camelCase, ExecutionTime isn’t there at all, and there’s an undocumented serverLogicName. Code written from the docs reads undefined for every field. Also note that data is your return value as a string, so the client parses twice: once for the envelope, once for your payload.

Errors have a twist too. Your code can’t set a status code. If you throw, the client always gets HTTP 400 with success: false and a generic “Exception occurred while processing this request”. Your message never leaves the server, which is good for security, but it also means a 400 from your own code looks exactly like the sandbox rejecting it. If you catch the exception and return an error object instead, the client gets HTTP 200 with success: true, and your error is just data. A client that only checks success treats it as a result.

So success tells you whether the platform ran your code, not whether your code succeeded. Wrap your own results in a shape the client can check ({ ok: true, data } / { ok: false, error }), log unexpected errors before you throw, and treat a 400 as “something unexpected happened, here is the requestId”.

Multi-level permissions break OData reads

Server Logic reads Dataverse through Server.Connector.Dataverse, and that connector goes through the same table-permission layer as the Power Pages Web API. So the Web API’s known issues come along for the ride.

I ran into this one with a fairly common permission chain: contact → nursery (Contact scope) → task (Parent scope). The endpoint returns the tasks of one type for one nursery. The client only sends the nursery; the task type is applied on the server, so users never see or change that filter. That’s the whole point of putting it in Server Logic. The obvious approach was an OData $filter:

js
Server.Connector.Dataverse.RetrieveMultipleRecords('tasks',
  '$select=subject&$filter=_dwcrm_nurseryid_value eq ' + nurseryId +
  ' and dwcrm_tasktype eq ' + TASK_TYPE);

Every OData read of the task table failed, with or without the $filter, and so did an $expand from the nursery:

txt
400 9004010D "Common Data Service error occurred"
0x80040216 entityRelationshipRole for given navigation property not found

It isn’t an activity quirk either: a custom child table under the same chain fails the same way, and so does a permission through Regarding instead of the custom lookup. The first level is fine - reading the nurseries returns only the user’s own nursery. Anything below it breaks.

This matches a known issue of the Web API: multi-level 1:N and N:N permissions with Parent, Contact or Account scope give a CDS error on GET. The documented workaround is FetchXML, and it works in Server Logic too:

js
// Applied on the server only: the client never sends or sees it
const TASK_TYPE = 860150000;
const GUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;

function get() {
  const nurseryId = (Server.Context.QueryParameters || {}).nurseryId || '';
  if (!GUID.test(nurseryId)) {
    return JSON.stringify({ ok: false, error: { code: 'invalid_nursery' } });
  }

  const fetchXml =
    '<fetch>' +
      '<entity name="task">' +
        '<attribute name="subject"/>' +
        '<filter>' +
          '<condition attribute="dwcrm_nurseryid" operator="eq" value="' + nurseryId + '"/>' +
          '<condition attribute="dwcrm_tasktype" operator="eq" value="' + TASK_TYPE + '"/>' +
        '</filter>' +
      '</entity>' +
    '</fetch>';

  const response = JSON.parse(Server.Connector.Dataverse.RetrieveMultipleRecords(
    'tasks', 'fetchXml=' + encodeURIComponent(fetchXml)));
  if (!response.IsSuccessStatusCode) throw new Error(response.ReasonPhrase);

  return JSON.stringify({ ok: true, data: JSON.parse(response.Body).value });
}

And, importantly, the permissions still apply. Even a FetchXML query with no nursery condition at all returned only the tasks of the user’s own nursery, so the table permissions, not the ID the client sends, decide which nurseries are visible. The task type never leaves the server, so the client can’t widen it. The nursery ID is the only value that comes from the browser and ends up inside the XML, so check that it’s a GUID before using it.

I hope Microsoft at least adds this to the Server Logic docs, the way it’s listed for the Web API. Knowing what works and what doesn’t before you hit it saves a lot of debugging.

Conclusion

I still think that Server Logic is the new default backend for Power Pages. Code that runs on behalf of the signed-in user, with their table permissions, behind an endpoint only the right web roles can reach, is exactly what we were missing. The rough edges are real, but each one has a workaround:

  • Write plain JavaScript with arrow functions or named declarations, and use flat endpoint names.
  • Don’t rely on live debugging yet; return or log the details you need instead.
  • Don’t trust success alone - wrap your results in your own { ok } shape.
  • If you have multi-level 1:N or N:N permission chains, use FetchXML instead of OData.

I hope Microsoft addresses these, or at least updates the docs to match how Server Logic actually behaves.

Next in Server Logic in Practice: a practical deep dive into calling Custom APIs and cloud flows from Server Logic, when to use which, and the pitfalls along the way. Subscribe so you don’t miss it.