Display Error , Warning , Info Notifications on form in CRM Using Java Script

Notifications
Hi ,

Notifications were first introduced in CRM 2013 as a new feature in the java script SDK.

The following line of code shows to display notification

Xrm.Page.ui.setFormNotification(message, level , Id)

Message : Text to be displayed

Level : ERROR ,INFO , WARNING (Will specify Icon)

Id : Identify notification for clearing it later,

Info
Xrm.Page.ui.setFormNotification("INfo Message", "INFO", "Info1");

Error :
Xrm.Page.ui.setFormNotification("Error Message","ERROR", "Err1");

Warning :
Xrm.Page.ui.setFormNotification("Error Message","WARNING", "Warn1");

Clear notification by Id
Xrm.Page.ui.clearFormNotification("Err1");
Xrm.Page.ui.clearFormNotification("Info1");
Xrm.Page.ui.clearFormNotification("Warn1");

How To : Get All Required Fields Using Java Script In CRM

Introduction :  Suppose you would like to get all the required fields on a form using java script.

Code:

var message = "The following fields are required:\n";
Xrm.Page.data.entity.attributes.forEach(function (attribute, index) {
if (attribute.getRequiredLevel() == "required")
{
message += "  \u2219 " + attribute.getName() + "\n";
}});
alert(message);

How To : Get Business Unit & Organization Id's of a Calling User in Microsoft Dynamics CRM 2011 in .NET With WhoAmIRequest

The following code will show you how to get Business Unit & Organization Id's of a Calling User in Microsoft Dynamics CRM 2011 in .NET With "WhoAmIRequest."

Code:

WhoAmIRequest Request = new WhoAmIRequest();
WhoAmIResponse Response= (WhoAmIResponse)_serviceProxy.Execute(Request);

Image

How To : Delete a Record in Microsoft Dynamics CRM Using .Net SDK

The following code will show you who to delete a record of any entity type using .Net.

Code:

// Create Request
DeleteRequest Request = new DeleteRequest();

// Set Target (record you want to delete)
Request.Target = new EntityReference("account", new Guid("72876387-9E5C-E111-B314-1CC1DEF1353B"));

// Execute Request
DeleteResponse Response = (DeleteResponse)_serviceProxy.Execute(Request);

Note: you can find A way to initialize a service proxy at the following link
http://crmprof.wordpress.com/2013/03/13/creating-organization-service-proxy-in-microsoft-dynamics-crm-2011/

 

How To : Check if an Entity can Participate in Many-To-Many Relationships in C# SDK

The following code shows how you can check if an Entity can be the Primary Entity in a Many-To-Many Relationship or not.

Code:

//Create The Request
CanManyToManyRequest Request = new CanManyToManyRequest();

//Set Entity Name
Request.EntityName = "account";

//Execute 
CanManyToManyResponse Response = (CanManyToManyResponse)_serviceProxy.Execute(Request);

//Get The Result
var result = Response.CanManyToMany;

 

How To : Check if an Entity can be the Primary Entity in a One-To-Many Relationship in CRM Using C# SDK

The following code shows how  to can check whether an Entity can be the Primary Entity in a One-To-Many Relationship or not.

Code:

  //Create Request
  CanBeReferencedRequest Request = new CanBeReferencedRequest();

 //Set Entity Name
Request.EntityName = "account";

 //Get Response
CanBeReferencedResponse Response = (CanBeReferencedResponse)_serviceProxy.Execute(Request);

 //Get Result
var result = Response.CanBeReferenced;