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 moreWe can help you with Model-Driven Apps Command Bar: A Guide to PrimaryControl and SelectedControl
If you want help implementing, troubleshooting, or improving this product, contact us and we’ll point you in the right direction.
Related posts
Copilot Studio: Agent Integration Approaches — Tools, Knowledge, and Agents
In Copilot Studio, agent integration employs the same fundamental integration concepts and patterns used in traditional enterprise integration...
Copilot Studio: How to Plan Integration with Enterprise Systems
Integrating Microsoft Copilot Studio agents with enterprise systems transforms a basic chatbot into a secure, intelligent digital teammate tha...
Book Review : The Manager 's Path : A Guide for Tech Leaders Navigating Growth and Change by Camille Fournier
After a long time, I came across a book that is truly valuable for engineering students and professionals, especially those working in t...
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...

