Loading...

Model-Driven Apps Command Bar: A Guide to PrimaryControl and SelectedControl

Model-Driven Apps Command Bar: A Guide to PrimaryControl and SelectedControl

The command bar in Power Apps model-driven apps is a toolbar that lets users perform actions. You can customize it by adding buttons that run your own logic, either using Power Fx or JavaScript. This logic can work with a single data record or multiple records, depending on where the button is placed.



The CrmParameter in the ribbon of Dynamics CRM (now Dynamics 365) is a special parameter used in the ribbon's button definitions or commands. It provides contextual information about the entity or record within the CRM system when the ribbon button is clicked.

Purpose of CrmParameter

CrmParameter is primarily used to pass specific CRM-related data to a custom JavaScript function, URL, or command action. It helps in retrieving dynamic data based on the current context, such as entity IDs, selected records, or even the page's user interface settings.


1. PrimaryControl

Definition: Refers to the main form context or entity record currently being displayed or interacted with in the app.

Purpose: Allows you to access and manipulate data on the form. For example, you can retrieve or update field values, interact with form controls, or trigger form actions.

Example Usage:

JavaScript

function runCommand(primaryControl) {

var formContext = primaryControl; // Get the form context

var accountName = formContext.getAttribute("name").getValue(); // Get a field value

alert("Account Name: " + accountName);

}


2. SelectedControl

Definition: Refers to the selected control or grid in a sub-grid or list view.

Purpose: Used to access records selected in a grid or list. It is useful for batch operations or commands that involve multiple records.

Example Usage:

JavaScript

function runCommand(selectedControl) {

    var selectedRows = selectedControl.getSelectedRows(); // Get selected rows in a grid
    selectedRows.forEach(function (row) {
        var data = row.getData();
        console.log(data.entityReference.id); // Get record IDs
    });
}


The PrimaryControl and SelectedControl parameters in the command bar of a Model-Driven App in Dynamics 365 are essential for customizing and extending app functionality. They provide critical context and enable developers to create dynamic, context-aware commands.

Published on:

Learn more
Power Platform , D365 CE & Cloud
Power Platform , D365 CE & Cloud

Dynamics 365 CE, Power Apps, Powerapps, Azure, Dataverse, D365,Power Platforms (Power Apps, Power Automate, Virtual Agent and AI Builder), Book Review

Share post:

Related posts

Power Platform Environment Deep Dive (Part 2)

In Microsoft Power Platform, choosing the right environment type is important because each environment is designed for a different business pu...

17 hours ago

Power Platform Environment Deep Dive (Part 1)

Today, in the business enterpriese world, Power Platform enables organization to build application, automate workflow, analyze data  crea...

2 days ago

Book Review : Life 3.0 by Max Tegmark

This is the third book I’ve read this year, and even though I’m still in the early chapters, it already feels like my favorite read of the yea...

1 month ago

Dataverse Views Demystified: Making Data Work for You

In Microsoft Dataverse, users do not always see all the data stored in a table. What they can view depends on their security permissions, role...

2 months ago

Decode & Fix : Shared App host initialization has timed out in Microsoft Power Apps

 Issue :While working with apps in the Microsoft Power Platform, we encountered a critical issue where the application failed to load pro...

4 months ago

Dataverse Integration Patterns: Sync vs Async vs Event-driven (Real Use Cases)

As organizations start using Microsoft Power Platform, Microsoft Dataverse is no longer just a place to store data—it becomes a key part of ho...

4 months ago

Book Review : Don't Believe Everything You Think by Joseph Nguyen

My second book of this year is "Don’t Believe Everything You Think" by Joseph Nguyen. This book was recommended by a friend who strongly belie...

5 months ago

Book Review : Scary Smart by Mo Gawdat

The first book I read in 2026 was Scary Smart by Mo Gawdat, the former Chief Business Officer at Google.In today’s world, Artificial Intellige...

6 months ago

Managing Temporary User Access in Dataverse with Access Teams

Access Teams let you give people access to one specific record, not the whole table.Access Teams in Microsoft Dataverse are a powerful way to ...

6 months ago

Newsletter

Get the latest Dynamics 365 and Power Platform content in your inbox

A curated digest of community blogs, product news, videos, and podcasts — delivered without the noise.

Weekly updates Unsubscribe anytime Fresh community picks
We use your email only for the newsletter and you can unsubscribe at any time.
By subscribing, you agree to the privacy policy.