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

Stay up to date with latest Microsoft Dynamics 365 and Power Platform news!
* Yes, I agree to the privacy policy