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});}
Published on:
Learn moreRelated 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...
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...
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...
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...
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...
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...
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...
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...
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 ...

