What End-to-End Development Services…
A software project rarely collapses because the code is wrong.…
Use Xrm.WebApi.online.execute(request) to call a Microsoft Dataverse custom API from JavaScript on an online Dynamics 365 model-driven form. If your development ticket says “Call Custom API from JavaScript Dynamics 365”, ask for the operation’s unique name, its inputs and an example of the response.
Imagine a returns agent opening a case in Dynamics 365 Customer Service. One click sends the case number to Dataverse and adds a return-label job to a queue. If the label never arrives, the agent can use the job number to find out whether the request reached the print team.
Open the custom API in the Power Apps solution for the environment you plan to test. Copy its Unique Name, including the publisher prefix. A button can say Request return label in any language. The script still needs the registered operation name, such as ops_QueueReturnLabel.
Check Is Function and Binding Type. A function uses HTTP GET to read data and must declare an output. An action uses POST and can change data. Creating a queue entry calls for an action. Binding determines the target. A global operation has no bound table. An entity-bound operation targets one row, and a collection-bound operation targets the table’s entity set.
For a public API, find its unique name in the environment’s $metadata document. The Action or Function entry lists the parameter names and types Dataverse expects.
In this hypothetical example, ops_QueueReturnLabel is a global action with one required string input named CaseNumber and one string output named JobNumber. Its plug-in creates the queue row and sets that output. To run the sample, deploy this action in your test environment or adapt the request to an action you already have.
Add the following script as a JavaScript web resource. In the command designer for the Case main form, create a command, choose Run JavaScript, select the library and enter opsQueueReturnLabel as the function name. Pass PrimaryControl as its first parameter. This gives the handler the form from which the agent clicked.
Include the Case Number column on that form. Its logical name is ticketnumber. Save and publish the web resource and command, then reopen the app so the form loads the published version.
class QueueReturnLabelRequest {
constructor(caseNumber) {
this.CaseNumber = caseNumber;
}
getMetadata() {
return {
operationName: “ops_QueueReturnLabel”,
operationType: 0,
boundParameter: null,
parameterTypes: {
CaseNumber: { typeName: “Edm.String”, structuralProperty: 1 }
}
};
}
}
async function opsQueueReturnLabel(primaryControl) {
const caseNumber = primaryControl.getAttribute(“ticketnumber”)?.getValue();
if (!caseNumber) {
return Xrm.Navigation.openAlertDialog({
text: “Case number unavailable. Check that the case is saved and Case Number is on the form.”
});
}
let message;
try {
const request = new QueueReturnLabelRequest(caseNumber);
const response = await Xrm.WebApi.online.execute(request);
const body = response.status === 204 ? null : await response.json();
const jobNumber = body?.JobNumber;
message = typeof jobNumber === “string” && jobNumber.trim()
? “Return label queued as ” + jobNumber
: “No job number returned. Check the queue before retrying.”;
} catch (error) {
message = “Check the label queue before retrying. ” + error.message;
}
return Xrm.Navigation.openAlertDialog({ text: message });
}
The class puts getMetadata() on the request prototype, where the client API expects it. For operationType, use 0 for an action or 1 for a function. Here, null means the call is unbound and structuralProperty: 1 marks CaseNumber as a primitive value. Only inputs belong in parameterTypes.
In a development environment, open a saved case and select the button once. Suppose case CAS-1042 returns job LBL-3108. Look up that job in the return-label queue. One new row carrying both numbers confirms which case was queued. The print team can use the job’s status to tell whether the label has printed.
HTTP 204 No Content means the action succeeded and returned an empty body. Calling response.json() on it can turn a successful action into a parsing error. Skipping the parser is correct for an action designed without outputs. The label action promises a job number, so an empty reply gives the agent a reason to check the queue before clicking again.
Open the browser’s Network panel before pressing the button. If no request for the operation appears, check the selected library, handler name and case number. If a request appears, its status and response message tell you where to look next.
“Request completed” leaves a returns agent guessing when the printer stays quiet. Ebtechsol suggests one last check before rollout. Give a support colleague the job number from the form and see whether they can find the right case in the queue.
The model-driven app manages authentication for a signed-in user’s form commands. A standalone web app needs its own authentication flow for the Dataverse Web API. Copying the form script there leaves it without the host’s Xrm object.
Xrm.WebApi.online.execute requires an online connection. If agents work offline, show that the action needs connectivity. Only display a job number once the server has actually returned one.
Use the binding parameter declared for the Case row. For a form command, primaryControl.data.entity.getId() returns the saved row’s GUID. Supply the row reference under the bound parameter and keep any other inputs separate.
An API marked Is Private is omitted from Dataverse’s $metadata document. Check the custom API record in the solution. For a function, also confirm that it declares at least one response property.
A custom API can run before a plug-in is attached. Dataverse then returns default output values. Check the API’s Plug-in Type and whether that implementation assigns OutputParameters[“JobNumber”] on the path the case took.
A form event receives an execution context when you enable that option. Use executionContext.getFormContext() to obtain the form. Keep label creation behind a deliberate click because reopening a case can fire its load event again.
Extend the action with a request identifier. Have the server enforce its uniqueness and return the existing job when a retry uses the same identifier. A deliberate reprint gets a fresh identifier.
A grid command receives grid context through SelectedControl. It needs code to read the selected rows and decide whether to process one case or several. The form handler reads a column from one open case.
This request sends only CaseNumber. A plug-in that looks up the address in Dataverse reads the stored value. If the label depends on a form edit, wait for the save to finish before submitting the job.
A ticket headed “Call Custom API from JavaScript Dynamics 365” needs the environment, operation name, time of the click and any HTTP status or error message. Include the test case number and any returned job number so support can trace that submission.
A software project rarely collapses because the code is wrong.…
Choosing the right software model can shape a company’s efficiency,…
EB Technical Solutions FZE /
EB TECHNICAL SOLUTIONS (PVT.) LIMITED
Copyright © 2026 EBTECHSOL


Ask me anything about AI Automation, API Integration, SaaS Development or our Services.
Just get in touch via text or microphone.