web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested Answer

A method to retrieve field values from a grid context via the ribbon

(0) ShareShare
ReportReport
Posted on by 2,175

Hi all,

Quick question. I've created a ribbon button available in the grid view, only appearing when a user selects one or more cases. This function allows a person to resolve all selected cases in the grid. Basically what I'm doing is that I'm passing through the ID of the selected cases by using the SelectedControlSelectedItemIds parameter which you can pass. I then use those IDs and a few other static variables to loop through the array of case IDs which then calls another function which uses the /api/data/v9.2/CloseIncident web API method.

This works fine. I'm now after a way to put in some conditions on what they can and cannot resolve based on certain fields on the case. This is fine with a form button as you can get the formContext which then allows you to get the values of fields on the form but I'm looking at the Grid Context which you can get from the SelectedControl parameter which you can pass via the ribbon. It's just I'm having trouble finding a way of retrieving certain attribute values from selected records in a grid to use as a check for whether selected case can be resolved. Can someone point me in the right direction on getting certain attribute values from selected records in a grid?

Would I need to create another function that uses the web API to loop through the selected record IDs and use the get value API method or is there a way to get attributes via the grid context? Does the field need to be visible on the grid? Below is the code snippet which works well for resolving selected cases from a grid.

async function ribbonGridResolve(SelectedControlSelectedItemIds, SelectedControl) {
    var subject = 'static subject'
    var billableHours = 60;
    var resolutionDescription = 'static description';
    var resolutionCode = 5;
    // Not sure whether I can use the gridContext to retrieve attributes from selected values
    var gridContext = SelectedControl;
    var i;
    Xrm.Utility.showProgressIndicator('Resolving');
    for (i = 0; i < SelectedControlSelectedItemIds.length; i  ) {
        var caseId = SelectedControlSelectedItemIds[i]
        var actualIndex = i   1;
        // This calls a separate function I created that specifically calls the web API closeincident method
        await closeCase(subject, caseId, billableHours, resolutionDescription, resolutionCode, SelectedControlSelectedItemIds.length, actualIndex);
    }

    Xrm.Utility.closeProgressIndicator();

}

I want to put in some additional checks within the for loop based on certain field values in each case but not sure how to retrieve attribute values in the grid and specifically for selected grid items.

I have the same question (0)
  • Suggested answer
    meelamri Profile Picture
    13,218 User Group Leader on at

    Hi, 

    If you want to put some additional check based on certain field, you have two options: 

    1. Add the necessary columns to your subgrid. 
    2. Perform a retrieve with Xrm.WebApi.retrieveRecord()

    I implement the second option in my environment, this is my sample code: 

    async function ribbonGridResolve(SelectedControlSelectedItemIds, SelectedControl) {
        var subject = 'static subject'
        var billableHours = 60;
        var resolutionDescription = 'static description';
        var resolutionCode = 5;
        // Not sure whether I can use the gridContext to retrieve attributes from selected values
        var gridContext = SelectedControl;
        var i;
        Xrm.Utility.showProgressIndicator('Resolving');
        for (i = 0; i < SelectedControlSelectedItemIds.length; i  ) {
            var caseId = SelectedControlSelectedItemIds[i]
            var actualIndex = i   1;
            var isEnabled = await isResolveEnabled(caseId);
            console.log(isEnabled);
            if (isEnabled) {
                // This calls a separate function I created that specifically calls the web API closeincident method
                //await closeCase(subject, caseId, billableHours, resolutionDescription, resolutionCode, SelectedControlSelectedItemIds.length, actualIndex);
                console.log("Case: " caseId " isEnabled")
            }
            else{
                var alertStrings = { confirmButtonLabel: 'Ok', text: "Case XXX can't be resolved" };
                var alertOptions = { height: 120, width: 260 };
                
                Xrm.Navigation.openAlertDialog(alertStrings, alertOptions).then(
                    function success() {
                        // perform operations on alert dialog close
                        
                    },
                    function (error) {
                        console.log(error.message);
                        // handle error conditions
                    }
                );
            }
    
        }
    
        Xrm.Utility.closeProgressIndicator();
    
    }
    
    async function isResolveEnabled(caseId) {
        console.log(caseId);
        var isEnabled = false;
        await Xrm.WebApi.retrieveRecord("incident", caseId, "?$select=description").then(
            function success(result) {
                if (result.description!=null && result.description.includes("approved"))
                    isEnabled = true;
            },
            function (error) {
                console.log(error.message);
                // handle error conditions
            }
        );
        return isEnabled;
    }
    

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Muhammad Shahzad Shafique Profile Picture

Muhammad Shahzad Sh... 69 Most Valuable Professional

#2
ManoVerse Profile Picture

ManoVerse 55 Super User 2026 Season 1

#3
11manish Profile Picture

11manish 37

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans