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

Notifications

Announcements

No record found.

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,983 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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 108 Super User 2025 Season 2

#2
Jimmy Passeti Profile Picture

Jimmy Passeti 50 Most Valuable Professional

#3
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 49 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans