What is the best way to set form notifications in MS CRM and remove them if the validation is complete?

What is the best way to set form notifications in MS CRM and remove them if the validation is complete?What is the best way to set form notifications in MS CRM and remove them if the validation is complete?

Microsoft Dynamics 365 (MS CRM) empowers users to manage valuable customer data. However, ensuring data accuracy requires clear communication during form entry. This is where form notifications become crucial. They provide real-time feedback, guiding users through the process and highlighting potential issues. But how do you create an optimal notification experience that disappears once validation is complete?

Form notifications serve a dual purpose:

  1. Guiding Users: They inform users about required fields, data entry formats, and general form expectations. This helps prevent errors from the outset.
  2. Highlighting Issues: They alert users to missing data, incorrect formats, or other validation failures. This allows for immediate correction before saving the record.

There are two primary notification types in MS CRM:

  • Form-Level Notifications: Displayed at the top of the form, providing a general message or reminder.
  • Field-Level Notifications: Associated with specific fields, pinpointing where an issue exists.

Best Practices for Setting Form Notifications:

  1. Identify Validation Requirements: Before implementing form notifications, clearly define the validation rules and requirements for the CRM form. Determine which fields need validation and the criteria for validation failure.

  2. Utilize JavaScript for Dynamic Notifications: JavaScript is a powerful tool for dynamically setting and removing form notifications based on user actions or data changes. Attach JavaScript functions to form events such as onchange or onsave to trigger notifications when needed.

  3. Provide Clear and Informative Messages: Craft form notification messages that are concise, descriptive, and user-friendly. Communicate the nature of the validation error or success message to guide users effectively.

  4. Use Different Notification Levels: MS Dynamics CRM supports different notification levels, including ERROR, WARNING, and INFO. Choose the appropriate notification level based on the severity of the message. For validation errors, use the ERROR level to alert users of critical issues.

  5. Consider Localization and Accessibility: Ensure that form notifications are accessible to all users, including those with disabilities. Use language and formatting that comply with accessibility standards and consider localization requirements for global deployments.

  6. Test Across Different Scenarios: Thoroughly test form notifications across various scenarios, including different user inputs and validation outcomes. Verify that notifications appear correctly, are triggered at the right time, and behave as expected under different conditions.

Let’s consider a scenario where a user is creating a new contact record. You want to ensure they fill in the required “Name” and “Email” fields.

function formOnSave(executionContext) {
  var requiredFieldName1 = "new_name";
  var requiredFieldName2 = "new_email";

  if (Xrm.Page.getAttribute(requiredFieldName1).getValue() === null ||
      Xrm.Page.getAttribute(requiredFieldName2).getValue() === null) {
    setFormNotification("Please fill in all required fields.", "ERROR", "requiredFieldsError");
  } else {
    Xrm.Page.ui.clearFormNotification();
    // Proceed with saving the record
  }

  executionContext.preventDefault();
}

Explanation:

  • The formOnSave function checks for missing values in the “Name” and “Email” fields.
  • If either field is empty, an error notification is displayed using setFormNotification.
  • Conversely, if both fields have values (else block), clearFormNotification removes any existing notification, allowing the record to be saved.

Leave a Reply

Your email address will not be published. Required fields are marked *