Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics 365 | Integration, Dataverse...
Suggested answer

Make all fields on the form to Upper case

(0) ShareShare
ReportReport
Posted on by

Hi All,

I am working on a requirement to make all the fields on the form to Upper case.

Can anyone help me with this ?

Thanks in advance !!

  • Suggested answer
    Wahaj Rashid Profile Picture
    Wahaj Rashid 11,321 on at
    RE: Make all fields on the form to Upper case

    Hi Sandeep,

    You can use JavaScript to change the field's text to Upper case.

    Please note, it only makes sense to do this for text fields.

    Let me explain:

    • Optionset: its better to change the actual option labels (because these are predefined values).
    • Lookups: primary field value is shown from the related entity.
    • Numbers: obviously no caps here.

    So to change the text fields to upper case, here is the logic:

    • On load of the form, loop through each attribute and attach on change event for text fields.
    • In the event handler, change the value to upper case.

    Here are steps to follow:

    • Create a web resource (JScript) or use existing. Add following sample code (you can change the names as per your need):


    // Register on Load of the Form, pass exuection context as first parameter
    function onLoad(executionContext) {
    
        // Get Form Context
        const formContext = executionContext.getFormContext();
    
        // Get Attriibutes collection
        const attributes = formContext.data.entity.attributes;
    
        // Attach On Change for all attributes
        attributes.forEach(addOnChangeForCaps);
    
    }
    
    // Attach On Change Function for string attributes.
    function addOnChangeForCaps(item, index) {
    
        
        const attribute = item;
    
        if (attribute.getAttributeType() === "string") {
            
            attribute.addOnChange(toCaps);
    
        }
    
    
    }
    
    // On change, set value to UPPER
    function toCaps(executionContext) {
    
        const attribute = executionContext.getEventSource();
    
        const attrValue = attribute.getValue();
    
        attribute.setValue(attrValue.toUpperCase());
    
    }
    
    

    • Register the first function (onLoad) on the on load event of the form, do not forget to pass execution context as first parameter.
    • Save and Publish the form (and web resource).

    Now, when the user types and leaves a text field, the value converts to the upper case automatically.

  • Sandeep Profile Picture
    Sandeep on at
    RE: Make all fields on the form to Upper case

    Hi Wajah,

    Thanks for your reply.

    Only the field values needs to be changed to upper case.

    Is it possible to change to upper case for all the data types which you mentioned ?

  • Wahaj Rashid Profile Picture
    Wahaj Rashid 11,321 on at
    RE: Make all fields on the form to Upper case

    Hi,

    Thank you for your query.

    Do you need to make the labels upper case or the field values?

    And when you say all fields, does it include optionsets, lookups, multiline texts?

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

Congratulations 2024 Spotlight Honorees

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December

Congratulations to our December super stars! 🥳

Start Your Super User Journey

Join the ranks of our community heros! 🦹

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,466 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans