Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Multiple Lines of Text - Line Break

(0) ShareShare
ReportReport
Posted on by

After creating a Mult Lines of Text field, how to write a JavaScript in such a way that while entering the text in the field, when we reach certain point (say some length of 15 or 20) the line should be break and start at next line?

*This post is locked for comments

  • Shahbaaz Ansari Profile Picture
    6,211 on at
    RE: Multiple Lines of Text - Line Break

    please can you share the code, it would be helpful.

  • Verified answer
    Community Member Profile Picture
    on at
    RE: Multiple Lines of Text - Line Break

    To these type of events we can use key press methods that helps to make actions dynamically when we entering the keys itself.

    msdn.microsoft.com/.../gg334266.aspx methods

  • Community Member Profile Picture
    on at
    RE: Multiple Lines of Text - Line Break

    Hi Shahbaaz,

    Actually my requirement is not that. I want the way that when we entering the keys/letters/characters in the field, it should dynamically get into new line when certain key length is reached. Hope you understand the requirement. For that we need to use "keypress" methods in MS CRM. You can find the theory here: msdn.microsoft.com/.../gg334266.aspx methods

    If you get the code by using that method, please share me.

    Thanks for reply!

  • Suggested answer
    Shahbaaz Ansari Profile Picture
    6,211 on at
    RE: Multiple Lines of Text - Line Break

    Hi Korada,

    You can try below java script code on change of your field(Multi line text).

    Note  : it will trigger on change of field,means once you complete full sentence then only it will break the sentence in new line.

    function enterNewLine(context)
    {

    var getDescriptionContext = context.getEventSource(); 
    if (getDescriptionContext.getValue() != null) { 
    var TempValue = getDescriptionContext.getValue() 
    try { 
    var newValue="";
    for(var i=0;i<TempValue.length;i++)

    newValue += TempValue.charAt(i);
    if (i%10 == 0 && i != 0) // check after how many char you want new line
    {
    newValue +="\n";
    }
    }
    Xrm.Page.getAttribute("description").setValue(newValue);
    }
    catch (e) {
    }
    }
    }

    Also you need to pass the context on the field change event like below screenshot,

    newline.PNG

    In my example i have used new line after 10 char you can change that in the above code in if (i%10 == 0 && i != 0)  condidtion.

    newline.PNG

    If you find it helpful, Please mark my answer as Verified

    If you still have any issue, please let me know.

    Best Regards,

    Shahbaaz

  • unizap Profile Picture
    on at
    RE: Multiple Lines of Text - Line Break

    Please refer msdn.microsoft.com/.../gg334481.aspx

    Here you can see all the supported events on which you can trigger your code. For your requirement, you would need to execute the code every time a character is typed on keyboard; the javascript event for that is  "onkeypress"; unfortunately crm does not support writing script on this event.

    So I am sure that executing any script on "onkeypress" is not recommended by Microsoft as the script may break in future updates of the product.

  • Community Member Profile Picture
    on at
    RE: Multiple Lines of Text - Line Break

    Thanks Mayank! But, are you sure about  developing that code is impossible and not recomended?

  • Suggested answer
    unizap Profile Picture
    on at
    RE: Multiple Lines of Text - Line Break

    there is no documented way of achieving this. you may achieve this by some unsupported lines of code, although that is not recommended.

    supported way would be to develop a custom control using a HTML web resource & programming the "onkeypress" event

    www.w3schools.com/.../event_onkeypress.asp

    Hope this helps.

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

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Microsoft Dynamics CRM (Archived)

#1
Mohamed Amine Mahmoudi Profile Picture

Mohamed Amine Mahmoudi 83 Super User 2025 Season 1

#2
Community Member Profile Picture

Community Member 52

#3
dkrishna Profile Picture

dkrishna 6

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans