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 :
Microsoft Dynamics CRM (Archived)

JavaScript to Convert First Letter of Each Word Of String To UpperCase

(0) ShareShare
ReportReport
Posted on by

I have create this code below

function UpperCaseField(fieldName) {
   var value = Xrm.Page.getAttribute(fieldName).getValue();
   //VALUE NOT NULL, CHANGE TEXT TO UPPERCASE
   if (value != null) {
      Xrm.Page.getAttribute(fieldName).setValue(value.charAt(0).toUpperCase() + value.substr(1).toLowerCase());
      Xrm.Page.ui.clearFormNotification('1');
   }
   //VALUE EQUAL TO NULL,DISPLAY WARNING NOTIFICATION
   else
   {
   	  Xrm.Page.ui.setFormNotification('Cannot be BLANK','WARNING','1');
   }
}

 That takes in the value from a text field and converts the First Letter of the first word of a string to uppercase. e.g, New york, it should be New York.

microsoft dynamic crm is the best -> Microsoft Dynamics Crm Is The Best .

I have tried multiple combinations , but none of them worked.

Can anyone help?

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Mohsin Ali Profile Picture
    3,634 on at

    Hope this will help you

    if (value != null) {

             Xrm.Page.getAttribute(fieldName).setValue(value.charAt(0).toUpperCase() + value.slice(1));

             Xrm.Page.ui.clearFormNotification('1');

          }

  • Verified answer
    Mahendar Pal Profile Picture
    45,095 on at

    Hi,

    Following code working fine for me:

    function UpperCaseField()

    {

    var Name=Xrm.Page.getAttribute("name").getValue();

    Xrm.Page.getAttribute("name").setValue(toTitleCase(Name));

    }

    function toTitleCase(str)

    {

       return str.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();});

    }

    Thanks

  • Community Member Profile Picture
    on at

    Hi Mohsin,

    Thanks :) ,

    but im getting an error , its says im missing ")", in this line?

            Xrm.Page.getAttribute(fieldName).setValue(value.charAt(0).toUpperCase() + value.slice(1););

  • Suggested answer
    Mohsin Ali Profile Picture
    3,634 on at

    here is the updated snippet.

    if (value != null) {

             Xrm.Page.getAttribute(fieldName).setValue(value.charAt(0).toUpperCase() + value.slice(1));

             Xrm.Page.ui.clearFormNotification('1');

          }

  • Community Member Profile Picture
    on at

    Hi HIMBAP,

    Thanks it worked. :)

  • JacquesNL Profile Picture
    800 on at

    [quote user="Mahender"]

    Hi,

    Following code working fine for me:

    function UpperCaseField()

    {

    var Name=Xrm.Page.getAttribute("name").getValue();

    Xrm.Page.getAttribute("name").setValue(toTitleCase(Name));

    }

    function toTitleCase(str)

    {

       return str.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();});

    }

    Thanks

    [/quote]

    Hi, this code works perfectly! But how can I edit it that it works when the field is empty?

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 > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans