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

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Javascript to convert case

(0) ShareShare
ReportReport
Posted on by

I'm attempting to use this Javascript, found from another post on this forum:

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();});

}

I have it on the on change event of a field named ist_name. It is configured like this:

configure1.png

And I get this error on loading the form:

0677.error1.png

What am I doing wrong?

*This post is locked for comments

I have the same question (0)
  • Mitch Milam Profile Picture
    on at
    RE: Javascript to convert case

    function upperCaseField(executionContext) {

       var field = executionContext.getEventSource()

       if (field.getValue() == null) {

           return;

       }

       field.setValue(field.getValue().toUpperCase());

    }

  • Mitch Milam Profile Picture
    on at
    RE: Javascript to convert case

    Hmm. You said that, but that is not the code you presented. Maybe you should steal better code next time. :)

    I'll see if I can't fix it tomorrow.

  • Cyclefitness Profile Picture
    on at
    RE: Javascript to convert case

    Thanks, everyone.  And thanks for the wrap-up, Mitch.  I did, however, want all UPPERCASE.   Can you modify your post to mention Debra wanted uppercase?. ;-)

  • Verified answer
    Mitch Milam Profile Picture
    on at
    RE: Javascript to convert case

    Hi Debra,

    This should tie it all together:

    http://www.infinite-x.net/2016/05/03/setting-a-dynamics-crm-fields-value-to-title-case-using-javascript

    Thanks,
    Mitch Milam
    xRM Coaches
    Microsoft MVP - CRM
    @MitchMilam
    http://blogs.infinite-x.net

  • Verified answer
    Aileen Gusni Profile Picture
    44,524 on at
    RE: Javascript to convert case

    Hi Debra,

    No need ()
    If you want to add another field, for robust solution, I suggest you use this method to auto-attach the onevent trigger:

    Xrm.Page.getAttribute(arg).addOnChange([function reference])
    msdn.microsoft.com/.../gg334409.aspx

    So example:
    Xrm.Page.getAttribute("field1").addOnChange(UpperCaseField)

    Hope this helps.
    Thanks

  • BharatPremji Profile Picture
    2,485 on at
    RE: Javascript to convert case

    Hi Debra,

    You could try something like this:

    dynamicscrmcoe.com/dynamics-crm-jrs-life-easier

    Bharat

  • Cyclefitness Profile Picture
    on at
    RE: Javascript to convert case

    Hi Raz:

    I guess it should, but then how can I reuse it on other fields?

  • Suggested answer
    BharatPremji Profile Picture
    2,485 on at
    RE: Javascript to convert case

    Hi Debra,

    When you call the function from CRM (your first screenshot) you do not need to () after the function name.

    So, in your case the value you put in the Function field is UpperCaseField not UpperCaseField()

    Bharat

  • Suggested answer
    razdynamics Profile Picture
    17,308 User Group Leader on at
    RE: Javascript to convert case

    Hi Debra shouldnt your variable be 'ist_name' instead of 'name'?  

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…

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
Aric Levin - MVP Profile Picture

Aric Levin - MVP 2 Moderator

#2
MA-04060624-0 Profile Picture

MA-04060624-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans