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)

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

I have the same question (0)
  • Suggested answer
    unizap Profile Picture
    on at

    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.

  • Community Member Profile Picture
    on at

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

  • unizap Profile Picture
    on at

    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.

  • Suggested answer
    Shahbaaz Ansari Profile Picture
    6,211 on at

    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

  • Community Member Profile Picture
    on at

    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!

  • Verified answer
    Community Member Profile Picture
    on at

    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

  • Shahbaaz Ansari Profile Picture
    6,211 on at

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

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