Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

CRM Javascript function GetLabel() gives too much back as result

Posted on by Microsoft Employee

Hello together

I have a problem with a function in the Xrm.Page-Library:

I want to fill the labels (display name) of all "recommended" fields in a string. Unfortunately, this function gives me not only the display name as result, but also the tooltip of the field.

Example:

Expected Result: "Accountname"

Result: "Accountname Type the company or business name."

I also get the tooltip text and that's wrong. The function GetLabel() should get me the label and not the description of the field.

Can you help me with this issue?

Code:

for (var i in attributes) {
        if (Xrm.Page.getAttribute(attributes[i].getName()).getRequiredLevel() == "recommended") {
            if (alertString == "") {
                alertString = Xrm.Page.getControl(attributes[i].getName()).getLabel();
            }
            else {
                alertString += ", " + Xrm.Page.getControl(attributes[i].getName()).getLabel();
            }
        }
    }

Thanks for your help :)

Kind regards, Dominik

*This post is locked for comments

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: CRM Javascript function GetLabel() gives too much back as result

    Hey Luke

    Thanks :) it works!

  • Verified answer
    Luke Sartain Profile Picture
    Luke Sartain 1,266 on at
    RE: CRM Javascript function GetLabel() gives too much back as result

    Yes, this annoyed me too.  Ended up using the split function to extract the label as follows:

    var label = Xrm.Page.getControl(field).getLabel();
    var fieldNameArray = label.split(/\n/);
    var fieldName = fieldNameArray[0];

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,240 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans