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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Answered

Field level notification

(0) ShareShare
ReportReport
Posted on by

Hello everyone,

I am trying to add field level notification to my crm contact form, so i wanted to be type INFO but it keeps showing an error message.

here's the code:

var pattern = /^((00)[0-9]{12})?(^[+][0-9]{12})?$/gm;
var fieldName = 'mobilephone';
var currentValue = formContext.getAttribute(fieldName).getValue();
if (pattern.test(currentValue)) {
formContext.getControl(fieldName).setNotification("Number is not in the right format", "INFO" ,"2");
} else {
formContext.getControl(fieldName).clearNotification("2");

0257.Capture.PNG

Appreciate your help!

I have the same question (0)
  • Charan Raju C R Profile Picture
    7 Moderator on at

    Hi Arura,

    Looks like the error appeared is not from your script, it is by the system's field validation. Could you please help me understand better by answering my queries below?

    1. What is the data type of Mobile Number field?

    2. What was the value you have keyed-in before getting this error notification?

    3. What are you trying to achieve using this javascript code?

  • Suggested answer
    Community Member Profile Picture
    on at

    Hi,

    According to the API(https://docs.microsoft.com/en-us/powerapps/developer/model-driven-apps/clientapi/reference/controls/setnotification), setNotification method only support 2 parameters.

    One parameter is your error message, another is the Notification ID which is used in clearNotification method.

    In your code, your Notification ID is "INFO" and you clear it with Notification ID "2". I think this caused your error. Also when the mobile phone matches your regular expression, you should clear notification not set.

    So please try this code:

    function formOnChange(executionContext){
    	var formContext = executionContext.getFormContext();
    	var pattern = /^((00)[0-9]{12})?(^[ ][0-9]{12})?$/gm;
    	var fieldName = 'mobilephone';
    	var currentValue = formContext.getAttribute(fieldName).getValue();
    	if(pattern.test(currentValue)){
            formContext.getControl(fieldName).clearNotification("2");
    	} else {
    	    formContext.getControl(fieldName).setNotification("Number is not in the right format","2");
    	} 
    }

    My test:

    When the mobile phone doesn't match regular expression:

    pastedimage1630465147971v1.png

    When the mobile phone matches regular expression:

    pastedimage1630465178275v2.png

  • Community Member Profile Picture
    on at

    Hi Charan,

    Thank you for your reply,

    1. the field is a single line of text

    2. I didnt enter anything because it's validating empty strings as well. Ps I changed the pattern to

    /^(^\s*$)?(^(00)[0-9]{12})?(^[+][0-9]{12})?$/ please if you can advise why its giving error for empty string

    but its still validating empty strings

    3. I am trying to give a warning message to user only if he enters a wrong value.

    Appreciate your help.

  • Community Member Profile Picture
    on at

    Hello Steve,

    Thank you for your reply,

    So what i understood from you that I cant display a warning or info message, it's only error message.

    because in my case I want the user to be able to save.

    Appreciate your help!

  • Verified answer
    Community Member Profile Picture
    on at

    Hi,

    If so, you can use addNotification method and set notificationLevel's value to 'RECOMMENDATION'.

    function formOnChange(executionContext){
    	var formContext = executionContext.getFormContext();
    	var pattern = /^((00)[0-9]{12})?(^[ ][0-9]{12})?$/gm;
    	var fieldName = 'mobilephone';
    	var currentValue = formContext.getAttribute(fieldName).getValue();
    	if(pattern.test(currentValue)){
                    formContext.getControl(fieldName).clearNotification("2");
    	} else {
                    formContext.getControl(fieldName).addNotification({"messages": ['Number is not in the right format'],"notificationLevel": 'RECOMMENDATION',"uniqueId": '2'});
    	} 
    }

    You can refer to this API doc https://docs.microsoft.com/en-us/powerapps/developer/model-driven-apps/clientapi/reference/controls/addnotification.

  • Community Member Profile Picture
    on at

    Hello Steve,

    Thank you so much it works!

    But I just want to ask is it possible to change the icon's position ?

    (I mean the warning icon that pops up once the user enters a wrong value

    Appreciate your help.

  • Community Member Profile Picture
    on at

    Hi,

    It seems no API can do this.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
ManoVerse Profile Picture

ManoVerse 101 Super User 2026 Season 1

#2
11manish Profile Picture

11manish 83

#3
Muhammad Shahzad Shafique Profile Picture

Muhammad Shahzad Sh... 69 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans