CRM Crate

(Field Notification) Using addNotification client API in Dynamics 365 CRM

In this course, we will learn to use the addNotification client API in Dynamics 365 CRM. Before we start, make sure to subscribe to CRM Crate.

Xrm.Utility.addNotification API in Dynamics 365

What is client API reference for model-driven apps?

  • The Client API object model also contains the Xrm.Internal namespace, and use of the objects/methods in this namespace isn’t supported. These objects, and any parts of the HTML Document Object Model (DOM), are subject to change without notice. We recommend that you don’t use these functions or any script that depends on the DOM.
  • Also, while debugging, you may find methods and objects in the Client API object model that aren’t documented. Only documented objects and methods are supported.
  • Most of the client scripting APIs available in this documentation also apply to Dynamics 365 Customer Engagement (on-premises). For a list of client scripting APIs not available for Customer Engagement (on-premises), see Client scripting reference for Dynamics 365 Customer Engagement (on-premises).

Undestanding the addNotification client API

The addNotification client API is used to display an error or recommendation notification for a control (Field) and lets you specify actions to execute based on the notification. The addNotification client API supports two type of notifications, the error notification and the recommendation notification.

API TypeSymbol
ErrorRed coloured icon “X”
RecommendationBulb shaped icon

Syntax for using client API

formContext.getControl(arg).addNotification(notification);

JavaScript Code Snippet for addNotification client in Dynamics 365 CRM

We have developed a JavaScript code for displaying a recommendation notification on field “Type” if value of field “Type” equals to “Mango”. A new”Apply” button is poped up in the recommendation bar. We have updated the field “Quantity” once the user clicks on the button “Apply”.

//CRM Crate JavaScript Snippet -
function CallMethod (executionContext) {

var formContext = executionContext.getFormContext();
var typefield = formContext.getControl("cc_type");
var typefieldValue = formContext.getAttribute("cc_type").getValue();
var quantity = formContext.data.entity.attributes.get("cc_quantity");  

//If Type == Mango.
    if (typefieldValue == 1 ) 
	{  
        var actionsCol = {  
            message: 'Do you want to place 100 quantity order?',  
            actions: null  
        };  
        actionsCol.actions = [function() {  
            quantity.setValue(100);  
            typefield.clearNotification('2002');  
        }];  
		
		//Utilizing addNotification client API.
        typefield.addNotification({  
            messages: ["Place 100 quantity order"],  
            notificationLevel: 'RECOMMENDATION',  
            uniqueId: '2002',  
            actions: [actionsCol]  
        });  
    }   
}
  • Let us now validate the above JavaScript in the Dynamics 365 CRM form. Navigate to the CRM and open the form where the above JavaScript has been deployed.
  • We will now trigger the JavaScript function by updating the field “Type” with value “Mango”. A new recommendation bulb is autopopulated with help of addNotification client API as shown below.
  • Click on the recommendation bulb, this will open the recommendation popup block as designed above.
  • Finally click on the button “Apply”, once we have clicked on “Apply” the field “Quantity” is set to value “100”.

Thus we learned to use the addNotification client API in Microsoft Dynamics 365 CRM.

5 2 votes
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
error: CRM Crate Security Engine - Disabled Right Click & Selection!

Congratulations!

Well Done,
Welcome to CRM Crate

Stay tuned with us and get all latest updates and learning in Microsoft CRM and related techonologes.