Getting Plural Names of Entities using WebApi

3 Comments

In Dynamics 365 / Power Apps, entity names can have various different plural extensions, such as “s”, “es”, “ies” etc. So when you’re writing code and you need the plural name of an entity dynamically, knowing only the singular name, how do you get it to ensuring you’re using the right name?

You can use Xrm.Utility.getEntityMetadata to get it. For example, with accounts below:

Xrm.Utility.getEntityMetadata("accounts", "")
    .then(function (result) {
        console.log("Entity Set Name: " + result.EntitySetName);
    }, function (error) {
        console.log(error);
    });

This produces:

A more interesting example, let’s say you have an entity called adobe_integrationsettings which may be installed. Note this name is already plural, though it is the logical name. Running this:

Returns a less obvious adobe_integrationsettingses.

 

THANKS FOR READING. BEFORE YOU LEAVE, I NEED YOUR HELP.
 

I AM SPENDING MORE TIME THESE DAYS CREATING YOUTUBE VIDEOS TO HELP PEOPLE LEARN THE MICROSOFT POWER PLATFORM.

IF YOU WOULD LIKE TO SEE HOW I BUILD APPS, OR FIND SOMETHING USEFUL READING MY BLOG, I WOULD REALLY APPRECIATE YOU SUBSCRIBING TO MY YOUTUBE CHANNEL.

THANK YOU, AND LET'S KEEP LEARNING TOGETHER.

CARL

https://www.youtube.com/carldesouza

 

ABOUT CARL DE SOUZA

Carl de Souza is a developer and architect focusing on Microsoft Dynamics 365, Power BI, Azure, and AI.

carldesouza.comLinkedIn Twitter | YouTube

 

3 Responses to Getting Plural Names of Entities using WebApi

  1. I remember a few other special examples:
    webresource -> webresourceset, opportunitycompetitors -> opportunitycompetitorscollection.
    Actually, for custom entities the EntitySetName can be changed.
    So, using the metadata is the only right way to get the plural name.

  2. Carl,
    Please correct the code if required, Xrm.Utility.getEntityMetadata(“accounts”, “”) should have probably used singular, screenshot looks fine by the way.

    Thanks
    Rk Hirpara

    • Agreed, it should be this:

      Xrm.Utility.getEntityMetadata(“account”, “”)
      .then(function (result) {
      console.log(“Entity Set Name: ” + result.EntitySetName);
      }, function (error) {
      console.log(error);
      });

Leave a Reply

Your email address will not be published. Required fields are marked *