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,...
Answered

Hiw to get the entity name from Grid view using JS

(0) ShareShare
ReportReport
Posted on by 1,023

Hi,

I have a custom button on the opportunity entity view. On click of the button, I want to do some operation. 

I am not sure how to get the entity name from the view through java script? Please advise the JS 

Thanks

I have the same question (0)
  • Suggested answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    James,

    There is no need in any JS - you can pass entity name as a parameter to your on click handler - it's in the list of "CRM Parameters" of Ribbon Workbench.

  • yify Profile Picture
    1,023 on at

    Andrew, through Ribbon command I am adding the parameter - Primary Control and Selected Entity Type Name.

    Could you please advise how my code should be at the grid level ?

    Currently I have this code to open Quick Create at the Form Level and I want to implement at Grid Level by passing the entity name dynamically.

       function openQuickCreate(PrimaryControl) {

           var formContext = PrimaryControl;

           var entityName = formContext.data.entity.getEntityName();

           var entityFormOptions = {};

           var formParameters = {};

           entityFormOptions['entityName'] = entityName;

           entityFormOptions['useQuickCreateForm'] = true;

           entityFormOptions['createFromEntity'] = formContext.data.entity.getEntityReference();

           Xrm.Navigation.openForm(entityFormOptions, formParameters).then(

               function () {

               },

               function (error) {

               });

       }

  • Verified answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Pass the PrimaryControl as you are doing to access the context and pass Selected Entity Type Name, just add it to the handler function like:

    function openQuickCreateFromGrid(PrimaryControl, SelectedEntityTypeName) {

    //use SelectedEntityTypeName in your code

    }

  • Verified answer
    Bipin D365 Profile Picture
    28,985 Moderator on at

    Hi,

    You can get entity name by adding the two more parameters in ribbon workbench

    1. PrimaryEntityTypeName

    2. SelectedEntityTypeName

    alert(PrimaryEntityTypeName);  //Lead

    alert(SelectedEntityTypeName);//competitor

    I have your code on competitor subgrid which is available on Lead entity. Please see below result for different parameters from subgrid button.

     

    function openQuickCreate(PrimaryControl,PrimaryEntityTypeName,SelectedEntityTypeName) {
    
    		alert(PrimaryEntityTypeName);  //Lead
    		console.log(PrimaryEntityTypeName);
    		alert(SelectedEntityTypeName);//competitor
    		console.log(SelectedEntityTypeName);
           var formContext = PrimaryControl;
    
           var entityName = formContext.data.entity.getEntityName();
    	   alert(entityName);
    	   console.log(entityName);
    
           var entityFormOptions = {};
    
           var formParameters = {};
    
           entityFormOptions['entityName'] = entityName;
    
           entityFormOptions['useQuickCreateForm'] = true;
    
           entityFormOptions['createFromEntity'] = formContext.data.entity.getEntityReference();
    
           Xrm.Navigation.openForm(entityFormOptions, formParameters).then(
    
               function () {
    
               },
    
               function (error) {
    
               });
    
       };

    If found helpful, Please mark my answer verified.

  • yify Profile Picture
    1,023 on at

    Thanks Andrew!! You are the CRM superman with all the powers :-)

  • yify Profile Picture
    1,023 on at

    Thanks Bipin for in detail steps, that helps.

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 March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
ManoVerse Profile Picture

ManoVerse 184 Super User 2026 Season 1

#2
11manish Profile Picture

11manish 138

#3
CU11031447-0 Profile Picture

CU11031447-0 100

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans