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)

restricting the field to 10 characters and showing error if it is less than 10

(0) ShareShare
ReportReport
Posted on by 1,023

Hi,

We have a requirement to restrict the field only to 10 characters and if the field is lees than 10 we need to show an erro on the screen.

I think showing error is not possible through business rule. Any guidance is highly appreciated.

Thanks!

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Alex Fun Wei Jie Profile Picture
    33,628 on at

    [quote][/quote]

    Hi,

    We have a requirement to restrict the field only to 10 characters and if the field is lees than 10 we need to show an erro on the screen.

    I think showing error is not possible through business rule. Any guidance is highly appreciated.

    Thanks!

    Hi,

    for Restriction to 10 characters, you can do it via field setting, the option is called maximum length,

    For less than 10 characters ,you can write a JS to achieve this.

    function CheckFieldLenght()

    {

    var value= Xrm.Page.getAttribute("accountnumber").getValue();
    if(value != null)
    {
    if(value.length < 10)
    {
    Xrm.Page.getControl("accountnumber").setNotification("your message");
    }
    else

    {

    Xrm.Page.getControl("accountnumber").clearNotification();

    }
    }

    else

    {

    Xrm.Page.getControl("accountnumber").setNotification("your message");

    }
    }



  • yify Profile Picture
    1,023 on at

    Hi Alex,

    I have used the code you have suggested and triggering on on save of the record. When the user enters less than 10 characters for the first time, its throwing error as per the requirement and when user edit it 10 characters, the error message is not going off. Please let me know if I doing anything wrong

    Thanks!

  • Alex Fun Wei Jie Profile Picture
    33,628 on at

    Hi,

    do you know how to debug the js?

  • Alex Fun Wei Jie Profile Picture
    33,628 on at

    Hi James,

    I've tried it, in my case, if the length is 10, the error will remove.

    https://youtu.be/4XGw8fDjZ-o

  • yify Profile Picture
    1,023 on at

    Alex, were you triggering the JS on only form Save or anything else?

  • Verified answer
    Alex Fun Wei Jie Profile Picture
    33,628 on at

    Hi,

    i trigger the JS during on change.

  • yify Profile Picture
    1,023 on at

    Thank you so much Alex, I really appreciate all your help in solving my problem.

    Thanks much!

  • yify Profile Picture
    1,023 on at

    And it worked :-)

  • Alex Fun Wei Jie Profile Picture
    33,628 on at

    Hi,

    No Problem. Enjoy XD

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