
Dynamics CRM Model Driven Apps provide a powerful platform for building custom business applications that work seamlessly with Microsoft Dynamics CRM services. One of the most important features in Dynamics CRM is the ability to show form notifications to users. Form notifications allow you to alert users when a specific event occurs in your form, there are 3 types of form notifications which you can display to end users i.e. Error, Warning and Information.
Often you may want user to perform a follow-up action on the notification like sending a follow-up email or deactivating the record or simply navigating to some external websites.
In this blog we will try to create a form notification on lead record that will be visible when lead is open for more that 10 days with a clickable button to navigate to email create form.
You will need to pass an additional parameter to setFormNotification api as below specification.
Method used in this blog is not documented on official client API documentation and hence considered as unsupported
Syntax
formContext.ui.setFormNotification(message, level, uniqueId, actions);
Parameter
| Name | Type | Required | Description |
|---|---|---|---|
| message | String | Yes | The text of the message. |
| level | String | Yes | The level of the message, which defines how the message will be displayed. Specify one of the following values:ERROR : Notification will use the system error icon.WARNING : Notification will use the system warning icon.INFO : Notification will use the system info icon. |
| uniqueId | String | Yes | A unique identifier for the message that can be used later with clearFormNotification to remove the notification. |
| actions | Array of Objects | No | Object Contains the following values: Label: (Optional) String. The label for the action in the message. Handler: (Optional) Function reference. The function to execute when the action label is clicked. |
Create a script
function createFormNotificationWithClickeableLink(executionContext) {
let formContext = executionContext.getFormContext();
formContext.ui.clearFormNotification("LeadWarning10Days");
let createdOn = formContext.getAttribute("createdon").getValue();
let daysOpen = Math.floor((new Date() - createdOn) / 86400000);
if (daysOpen > 10) {
formContext.ui.setFormNotification(
`This lead has been open since last ${daysOpen}, please send a followup email to customer.`,
"INFO",
"LeadWarning10Days",
[
{
Label: "Send Followup Email",
Handler: createEmail,
},
]
);
}
}
function createEmail(executionContext) {
let formContext = executionContext.getFormContext();
let entityFormOptions = {};
entityFormOptions["entityName"] = "email";
let formParameters = {};
formParameters["subject"] = "Folloup email from form notification";
formParameters["description"] =
"Default values for this record were set programmatically.";
formParameters["regardingobjectid"] =
formContext.data.entity.getEntityReference().id;
formParameters["regardingobjectidname"] =
formContext.data.entity.getEntityReference().name;
formParameters["regardingobjectidtype"] =
formContext.data.entity.getEntityReference().entityTame;
Xrm.Navigation.openForm(entityFormOptions, formParameters);
}
Call the method on load of the form

Notification with Action Button















/cdn.vox-cdn.com/uploads/chorus_asset/file/13622171/Screen_Shot_2018_12_12_at_3.02.26_PM.png)


