Introduction:
In Dynamics 365 CRM to show notifications beside CRM Field clearly on which field error occurred rather than showing all errors at the top of the CRM Forms, web resources of type JavaScript was used to build this. As an example, contact form and contact entity record used to show error notifications beside title field using set Notification if at all title was not mentioned on the contact form then error notification will be shown.
Step 1:
Login to the required environment and select required solution [Contact Customizations Solution in this case] as shown in the below figure.

Step 2:
After Step 1, select contact web resource in solution and click on Edit as shown in the below figure.

Step 3:
After Step 2, in contact webresource logic to be written on the field jobtitle by using getcontrol in formcontext a variable will be assigned like below
var jobtitlecontrol=formContext.getControl(“jobtitle”);
As shown in the below figure

Step 4:
After Step 3, in case if job title is not present then in order to provide error beside title field we have to use set Notification which expects couple of parameters message and uniqueid
formContext.getControl(arg).setNotification(message,uniqueId);
as
jobtitlecontrol.setNotification(“Job title Mandatory- Error notification.”,”jobtitlecontrolnotification”);
As shown in the below figure

Step 5:
After Step 4, final code looks like this under any method which is called under on change of title field and contact form load as
function jobtitlemandatorylogic(executionContext) {
var formContext = executionContext.getFormContext();
if (formContext !== null && formContext != ‘undefined’)
{
var jobtitle = formContext.getAttribute(“jobtitle”).getValue();
var jobtitlecontrol=formContext.getControl(“jobtitle”);
console.log(‘job title-‘ + jobtitle);
if (jobtitle == null)
{
formContext.ui.setFormNotification(“Job title Mandatory- Error notification.”, “ERROR”, “JobTitleMandateNotification”);
jobtitlecontrol.setNotification(“Job title Mandatory- Error notification.”,”jobtitlecontrolnotification”);
}
else
{
formContext.ui.clearFormNotification(“JobTitleMandateNotification”);
jobtitlecontrol.clearNotification(“jobtitlecontrolnotification”);
}
}
}
As shown in the below figure

Step 6:
After Step 5, save and publish webresource and open contact record and observe if at all no title present then one can observe error title beside that field as shown in the below figure

Note:
- Make sure to publish all customizations and upload JavaScript (js) file.
- Here I have concentrated more on showing notifications at field level, and the above function should be called from onchange event of contact title field & contact onload form event.
- Microsoft documentation found here
Conclusion: In this way, one can easily use show notifications in web resource beside CRM Entity field other than showing all the errors at the top of the form as form level easily.
Pingback: Back To Basics :Curated List of Articles in a Single Page – Common Man Tips for Power Platform, Dynamics CRM,Azure
Pingback: Rewind March 2022 – Common Man Tips for Power Platform, Dynamics CRM,Azure
Pingback: Rewind March 2022 - Microsoft Dynamics CRM Community
Pingback: Rewind March 2022 - Microsoft Dynamics CRM Community