LogoLogo

Our Products

Metadata Browser

Edge Add-on

HTML To PDF Converter

Power Automate Connector

Data Mask for Dataverse

Dataverse App

Commission 365

Dynamics 365 App

AI Autocloser

Dataverse App

Flow Monitor

Power Automate App

ServicesAboutCareersBlogContact
Chat on Teams
Metadata BrowserHTML To PDF ConverterData Mask for DataverseCommission 365AI AutocloserFlow Monitor
ServicesAboutCareersBlogContactChat on Teams
HomeBlogBuild a Modern Webpage Dialog in Dynamics 365 Using Ribbon Commands and JavaScript

Build a Modern Webpage Dialog in Dynamics 365 Using Ribbon Commands and JavaScript

May 24, 2026
#Dynamics 365
Chetan Jha
Build a Modern Webpage Dialog in Dynamics 365 Using Ribbon Commands and JavaScript

Introduction

Sales and service teams working in Dynamics 365 often need to assign follow-up tasks while staying on an Account record. This guide walks you through building a Create Task button on the Account command bar that opens a custom HTML web resource webpage. Users fill in task details and submit — the Task is created in Dataverse and linked to the Account automatically, without navigating away from the form.

Business Scenario

The standard New Task button in Dynamics 365 takes users away from the Account form, breaking their context. The goal is to replace that with a dedicated Create Task button that opens a modern webpage form in a separate window. On submit, the task is created via the Dataverse Web API and linked to the Account through the Regarding field. The Account timeline refreshes immediately to show the new task.

Entity

Logical Name

Account

account

Task

task

Task Field

Back to all articles

More from the blog

Securing a SharePoint List Using Security Groups

Sending a Feedback Survey Using Customer Voice in Dynamics 365

Enable Audio Playback in Dynamics 365 Contact Forms Using JavaScript

Generate Temporary Download URLs in Dynamics 365 Using GetFileSasUrl

Email Smarter in Outlook with Sales Copilot and Power Apps Integration

Creating And Embedding a Copilot Bot in Dynamics 365

Close Case on condition using Power Automate

Understanding and Using Polymorphic Lookups in Dynamics 365 with XrmToolBox

Need help with your business solution?

Our team can help you implement the right solution for your organization.

Get in touch
LogoLogo

Ex-Microsoft experts helping businesses get more from their Dynamics 365 and Power Platform investments.

Products

Logical Name

Subject

subject

Description

description

Due Date

scheduledend

Priority

prioritycode

Duration

actualdurationminutes

Regarding (link to Account)

regardingobjectid_account@odata.bind

Prerequisites

  • A Microsoft 365 account with Dynamics 365 and Power Apps access

  • Access to make.powerapps.com and an active Dataverse environment

  • Permission to create and publish solutions and web resources

  • Basic familiarity with Model-Driven Apps and JavaScript

Publisher Prefix: Throughout this guide, the prefix testpubl_ is used. Replace this with your own publisher prefix wherever you see it in web resource names.

Step-By-Step Guide

Step 1: Create the JavaScript Web Resource

Inside your solution, click New, hover over More, and select Web resource.

Field

Value

Display Name

Account Task Handler JS

Name

testpubl_new_accounttaskhandler (use your publisher prefix)

Type

Script (JScript)

Paste the following JavaScript into the editor:

var TaskHandler = TaskHandler || {};
 
TaskHandler.Ribbon = {
 
    openCreateTaskDialog: function (primaryControl) {
 
        if (!primaryControl) {
            Xrm.Navigation.openAlertDialog({ text: "Form context not available.", title: "Error" });
            return;
        }
 
        var formContext = primaryControl;
 
        var rawId = formContext.data.entity.getId(); // GUID of the currently open record
 
        if (!rawId || rawId.trim() === "") {
            Xrm.Navigation.openAlertDialog({ text: "Please save the Account record first.", title: "Record Not Saved" });
            return;
        }
 
        var accountId   = rawId.replace(/[{}]/g, "").toLowerCase().trim();
        var accountName = formContext.data.entity.getPrimaryAttributeValue() || "";
 
        var dataParam =
            "regardingId="    + encodeURIComponent(accountId) +
            "&regardingName=" + encodeURIComponent(accountName) +
            "&regardingType=account"; // CHANGE: update to contact, opportunity etc. if needed
 
        Xrm.Navigation.openWebResource(
            "testpubl_new_createtaskdialog", // CHANGE: use your publisher prefix + HTML web resource name
            { height: 580, width: 720 },
            dataParam
        );
    }
};

primaryControl — Passed by Command Designer when Parameter Type is PrimaryControl. Gives access to the current open form and record.

getId() — Reads the GUID of the open Account record. This ID is sent to the HTML page as regardingId so it can link the new Task.

"testpubl_new_createtaskdialog" — Logical name of the HTML web resource created in Step 2. Change the prefix to match your publisher.

height / width — Controls the webpage size in pixels. Adjust to suit your screen layout.

Click Save and then Publish.

Step 2: Create the HTML Web Resource (Webpage UI)

This is the webpage users see when they click the ribbon button. It opens in a separate browser window with its own URL. It contains the Task form fields, client-side validation, and the Dataverse Web API call that creates the Task.

Inside your solution, click New, hover over More, and select Web resource again.

Field

Value

Display Name

Create Task Dialog HTML

Name

testpubl_new_createtaskdialog (use your publisher prefix)

Type

Webpage (HTML)

The complete HTML file includes a full custom UI — dark header, progress bar, grouped field cards, real-time validation, and a success overlay. The structure below shows the key sections. Build the UI using the CSS variables in :root {} — change --accent, --ok, and --warn to match your brand colors.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8"/>
    <title>Create Task</title>
    <script src="ClientGlobalContext.js.aspx"></script>
    <link href="https://fonts.googleapis.com/css2?family=DM+Sans:wght@300;400;500;600&family=DM+Mono:wght@400;500&display=swap" rel="stylesheet">
    <style>
        :root {
            --accent:  #2563ff;
            --warn:    #e53e3e;
            --ok:      #16a34a;
            --surface: #f7f5f2;
            --card:    #ffffff;
            --border:  #e4e0db;
            --ink:     #0f0f0f;
        }
        /* Full CSS styles are in the complete web resource file */
    </style>
</head>
<body>
    <div class="success-overlay" id="success-overlay"> ... </div>
    <div class="header"> ... </div>
    <div class="progress-track">
        <div class="progress-fill" id="progress-fill"></div>
    </div>
    <div class="body">
        <div class="field-group"> ... </div>
        <div class="field-group"> ... </div>
    </div>
    <div class="footer"> ... </div>
    <script>
        // parseAllParams()
        // initDialog()
        // updateProgress()
        // validate()
        // submitTask()
    </script>
</body>
</html>

ClientGlobalContext.js.aspx — Must be the first script tag. Without it, Xrm.Utility.getGlobalContext() fails and no Task can be created.

parseAllParams() — Reads regardingId and regardingName from the URL. Xrm.Navigation.openWebResource wraps parameters under a Data= key — this function handles that correctly.

submitTask() — To link to Contact instead of Account, change regardingobjectid_account@odata.bind to regardingobjectid_contact@odata.bind and /accounts( to /contacts(.

Click Save and then Publish.

Step 3: Add the Ribbon Button Using Command Designer

In the App Designer, find the Accounts view in the navigation panel. Click the three dots next to it, hover over Edit command bar, and click Edit.

img1

In the Edit command bar for Accounts dialog, select Main form and click Edit.

img2

The Command Designer opens. Click New and select Command from the dropdown.

img3

Your new command appears in the command bar preview.

img4

In the Command panel on the right, configure the following settings:

Field

Value

Label

Create Task

Icon

Choose any Fluent icon from the dropdown

Action

Run JavaScript

Library

testpubl_new_accounttaskhandler (your JS web resource)

Function name

TaskHandler.Ribbon.openCreateTaskDialog

Parameter 1 Type

PrimaryControl

Visibility

Show

Tooltip title

Create a New Task

Click Save and Publish in the top right corner of the Command Designer.

img5
Step 4: Test the Solution End to End

Open your Model-Driven App. In the left navigation, click Accounts and open any existing Account record. The Create Task button appears in the command bar.

img6

Click Create Task. A new browser window opens showing the Account name in the dark header. The progress bar tracks field completion and the counter updates in real time.

img7

Fill in Subject, Due Date, and Priority. Click Create Task. On success, a full-screen dark confirmation overlay appears confirming the Task was created and linked to the Account.

img8

The webpage closes automatically after 2 seconds. The Account form timeline refreshes and the new Task appears under the Recent section.

Conclusion

By combining ribbon commands, JavaScript web resources, and the Dataverse Web API, you can build reusable webpage experiences that keep users in context without third-party tools. The same pattern works on Contact, Opportunity, or any other entity by updating the entity reference in two lines of code. Try it in your next project and share your experience in the comments.

Frequently Asked Questions (FAQ)

1. Why does my webpage show Unknown Account?

The most common cause is the Parameter Type in the Command Designer being set to String instead of PrimaryControl. Go to the Command Designer, find your Create Task command, scroll to Parameter 1, and confirm the type is PrimaryControl with no value entered. Save and Publish again.

2. Why does the webpage appear blank when it first opens?

A blank page is almost always a mismatch between the web resource logical name in the JavaScript and the actual name registered in the solution. Verify that the name passed to Xrm.Navigation.openWebResource exactly matches the Name field of your HTML web resource, including the publisher prefix — for example testpubl_new_createtaskdialog.

3. Can I use this on the Contact or Opportunity form?

Yes. The JavaScript reads the form context generically and works on any entity. In the HTML web resource, change regardingobjectid_account@odata.bind to regardingobjectid_contact@odata.bind and /accounts( to /contacts(. Then register a new ribbon command on the Contact table pointing to the same two web resources.

4. The Task is created but not showing in the Account timeline. Why?

The timeline refresh relies on window.opener.Xrm.Page.data.refresh(false) being called after the Task is created. If the Account form was opened in a new tab or the browser blocked the opener reference, this call silently fails. Manually refresh the Account form and the Task will appear.

Metadata Browser
  • HTML To PDF Converter
  • Data Mask for Dataverse
  • Commission 365
  • AI Autocloser
  • Flow Monitor
  • Services

    • D365 Marketing
    • D365 Sales
    • D365 Customer Service
    • D365 Field Service

    Company

    • About Us
    • Blog
    • Contact
    • Careers

    Copyright ©2026 Pascalcase Software Private Limited. All rights reserved.

    Privacy PolicyTerms of Service