Tuesday, 4 February 2014

New JavaScript methods in Microsoft Dynamics CRM 2013

 Microsoft Dynamics CRM 2013 is providing some exciting new methods we can use with the JavaScript SDK on the entity forms, such as :
  • Easier way to set the form dirty
  • Custom lookup filters
  • Displaying form notifications as well as field specific notifications. 
  • Xrm.Page.context.client.getClient()
    • Returns “Outlook”, “Web”, or “Mobile”
  • Xrm.Page.context.client.getClientState()
    • Returns “Online” or “Offline”
    • Xrm.Page.context.isOutlookOnline and isOutlookClient are now deprecated
  • Xrm.Page.data.refresh()
    • Asynchronously refresh data on form without reloading the page
    • Can pass in a callback to execute on error or success
  • Xrm.Page.data.save()
    • Asynchronously save the form
    • Can pass in a callback to execute on error or success
  • Xrm.Page.data.getIsValid()
    • Returns a boolean telling whether the form can be saved or not
  • Xrm.Page.data.setFormDirty()
    • Sets the form as dirty
  • Xrm.Page.data.entity.getPrimaryAttributeValue()
    • Returns a string value of the primary attribute for the entity
  • Xrm.Page.ui.setFormNotification()
    • Takes in a string value to set a form notification with the passed in string
    • Pass in “ERROR”, “INFORMATION” or “WARNING” to dictate the type of notification
  • crm 2013
  • Xrm.Page.ui.clearFormNotification()
    • Clears the form notification
All Controls
  • Xrm.Page.getControl(“new_name”).setNotification(“Field specific notification”)
    • Sets a notification specific to the field
  • crm 2013
  • Xrm.Page.getControl(“new_name”).clearNotification()
    • Clears the field specific notification
Number Fields
  • Xrm.Page.getAttribute(“new_precision”).setPrecision(2)
    • Override field’s precision
Date Fields
  • Xrm.Page.getControl(“createdon”).setShowTime(true)
    • Controls whether to show the time for a date field
Lookup Fields
  • Xrm.Page.getControl(“ownerid”).addCustomFilter(fetchFilter, entityType)
    • Applies a custom filter to the lookup view
    • entityType is optional and if it is not passed it will default to all entity views
  • Xrm.Page.getControl(“ownerid”).addPreSearch(handler)
    • triggers right before a lookup dialog pops open
  • Xrm.Page.getControl(“ownerid”).removePreSearch(handler)
    • removes event handler set from the addPreSearch method
  • Xrm.Utility.openWebResourceDialog(webResourceName, webResourceData, width, height)
    • opens a specified HTML web resource as a dialog

Tuesday, 10 December 2013

Restrict Auto Save in MSCRM 2013

function stopAutoSave(context) {
    var saveEvent = context.getEventArgs();
    if (saveEvent.getSaveMode() == 70) { //Form AutoSave Event
        saveEvent.preventDefault(); //Stops the Save Event

Sunday, 8 December 2013

Creste Email using CRM 2011 Plug In

private void SendEmail(IOrganizationService service, Guid recieverUserId, Guid senderUserId, Guid regardingObjectId, string emailBody, string emailSubject)
Entity email = new Entity();
email.LogicalName = “email”;
//Set regarding object property (i.e. The entity record, which u want this email associated with)
EntityReference regardingObject = new EntityReference(“{entity_name}”, regardingObjectId);
//Defining Activity Parties (starts)
EntityReference from = new EntityReference(“systemuser”, senderUserId);
EntityReference to = new EntityReference(“systemuser”,recieverUserId);
//Derive from party
Entity fromParty = new Entity(“activityparty”);
//Derive to party
Entity toParty = new Entity(“activityparty”);
toParty.Attributes.Add(“partyid”, to);
EntityCollection collFromParty = new EntityCollection();
collFromParty.EntityName = “systemuser”;
EntityCollection collToParty = new EntityCollection();
collToParty.EntityName = “systemuser”;
email.Attributes.Add(“to”, collToParty);
//Defining Activity Parties (ends)
//Set subject & body properties
email.Attributes.Add(“description”, emailBody);
//Create email activity
Guid emailID = service.Create(email);
//Sending email
SendEmailRequest reqSendEmail = new SendEmailRequest();
reqSendEmail.EmailId = emailID;//ID of created mail
reqSendEmail.TrackingToken = “”;
reqSendEmail.IssueSend = true;
SendEmailResponse res = (SendEmailResponse)service.Execute(reqSendEmail);

Wednesday, 4 December 2013

how to refresh parent ms crm 2011 form on child aspx custom page close?


I have button custom button in contract entity ribbon area. (MS CRM 2011).

In that button click I am opening an .aspx page through “window.showModalDialog”.

In the .aspx I want to access the contract entity record some attributes to set values for it.

But I am unable to access the CRM from.

I have tried like

window.top.opener.document.getElementById("'iaah_cohortyesclicked'").value = "value";

It is not working.


In the contract entity javascript where I am opening the window.showModalDialog

Now I am passing the CRM form windows object as parameter to showModalDialog.

//In javascript

window.showModalDialog(strSourceURL,window, "dialogHeight:200px;dialogWidth:550px;center:yes; resizable:0;maximize:0;minimize:0;status:no;scroll:no");

Before I was opening the dialog as

window.showModalDialog(strSourceURL,null, "dialogHeight:200px;dialogWidth:550px;center:yes; resizable:0;maximize:0;minimize:0;status:no;scroll:no");

Instead of null I am passing window.

Now I can able to access the CRM form attributes in my .aspx page.


var parentWindow = window.dialogArguments;