"тнιѕ вℓσg ¢συℓ∂ ѕανє уσυя мσηєу ιƒ тιмє = мσηєу" - ∂.мαηנαℓу

Thursday 14 November 2013

Form Notification in CRM 2013 using Javascript OR How to Display Form Level Notifications in CRM 2013 using Javascript

For Field Level Notifications, please refer the below post.


Form Notification is an interesting feature in CRM 2013.

Syntax:
Xrm.Page.ui.setFormNotification(message, level, uniqueId);
message- string
uniqueId- string
level - string, possible values are given below.
Following are the 3 possible form notifications ( Called Levels )
 ( CRM 2013 SDK )
  • ERROR : Notification will use the system error icon.
  • WARNING : Notification will use the system warning icon.
  • INFO : Notification will use the system info icon.
Lets try to understand this with a sample scenario. And later you could make changes as per your scenario.

Scenario: We have Credit limit and Annual revenue fields on the Account form. If the user enters a credit limit value greater than annual income and try to save the form, we need to notify the user with a message that the credit limit shouldn't cross the Annual revenue value. 

Here is the js code to display a 'Warning' notification.

function onSaveSetCreditLimitFormNotification()
{
var annualRevenue=Xrm.Page.getAttribute("revenue").getValue();
var creditLimit= Xrm.Page.getAttribute("creditlimit").getValue();

if(creditLimit > annualRevenue)
{
Xrm.Page.ui.setFormNotification("Sorry, Credit Limit should be less than the Annual Income","WARNING","CreditlimitMessage");

}
else
{
Xrm.Page.ui.clearFormNotification("CreditlimitMessage");

}

}

In this case, we would call the function on the Onsave event of the form ( Account )

We need to include this code in a Webresource file and make the function call as shown below.




Save the form and  Publish it.The next step is to test the results.


So we got the warning notification as shown. And notification gets cleared for the right value.


Similarly we could have info notification

Xrm.Page.ui.setFormNotification("Sorry, Credit Limit should be less than the Annual Income","INFO","CreditlimitMessage");

For which we gets the below info notifcation.


Error notification is also possible as show below.

Xrm.Page.ui.setFormNotification("Sorry, Credit Limit should be less than the Annual Income","ERROR","CreditlimitMessage");




No comments:

Post a Comment