Advertisements

Archive

Archive for January, 2014

Get the view name of main grid using JScript

January 29, 2014 Leave a comment

We got a requirement to Enable\disable ribbon button based on selected view.

View name

View name

We used JScript to disable the button by getting the selected view name.

Below is the script to get the selected view name of  Main Grid

var viewName = “”;

if (crmGrid && crmGrid.control) {

viewName = crmGrid.control.get_viewTitle();

}

🙂

Advertisements
Categories: CRM, JScript Tags: , ,

Disabling Activities rollup view option using Jscript

January 23, 2014 Leave a comment

In CRM, when you choose ‘Related “Regarding” Records’ option from ‘Activities’ left navigation of Account form, It loads Activities rollup view.

Activities Rollup view option

Activities Rollup view option

Recently we got a requirement to disable rollup option.

So we used below script to remove the ‘Related “Regarding” Records’ option from “Include” dropdown.

document.getElementById(“navActivities”).onclick = function () {

Mscrm.Details.loadArea(this, “areaActivities”);

document.getElementById(“areaActivitiesFrame”).onreadystatechange = function () {

if (this.readyState == “complete”) {

var doc = this.contentWindow.document;

var filterOn = doc.getElementById(“crmGrid_Account_ActivityPointers_ViewControl”);

filterOn.value = “ImmediateRelatedView”;

filterOn.options.remove(1);

// Refresh the grid

var evt = document.createEvent(“HTMLEvents”);

evt.initEvent(“change”, false, true);

filterOn.dispatchEvent(evt);

}

};

};

How do I use the script

  • Put the above script on form’s onload event
  • After the execution of script form looks as below
Hide 'Related Records'

Hide ‘Related Records’

What  are we doing in script

  • Get the Activities IFrame id (i.e., areaActivitiesFrame)
  • When the IFrame load completes (i.e., readyState == “complete”)
    • Get the “Include” dropdown control (i.e., ‘crmGrid_Account_ActivityPointers_ViewControl’)
    • Remove the ‘Related “Regarding” Records’  option

Note – The above script is unsupported which is not recommended and works for pre & post UR 12

Auditing User’s Team membership in CRM

January 20, 2014 Leave a comment

Recently we got a requirement to track Team membership of a User (i.e., Log when a User gets Add/Remove from a Team).

We checked whether the OOB Audit feature would fulfill this requirement.

Audit feature does logs an entry every time we add/remove a User from Team but as separate events.

Add User to a Team – Audit

  • An entry with Event name ‘Associate Entities’ gets created in Audit History
  • On double click on the entry you get below window with details of Team that User added to.
Audit Log-Add User to Team

Audit Log-Add User to Team

Remove User from a Team – Audit

  • An entry with Event name ‘Disassociate Entities’ gets created in Audit History
  • On double click on the entry you get below window with details of Team that User removed from.
Audit Log- Remove User from Team

Audit Log- Remove User from Team

 

More Info

  • Audit feature provide details of User’s Team membership, but not in a detailed manner.
  • Also ‘Associate Entities & Disassociate Entities‘ event’s will get logged in ‘Audit History’ every time you perform Associate\Disassociate operations with your N:N related entities.
  • If the details provided in Audit does not give you more details, You can go for a Plugin to log more details when User gets Add/Remove from a Team.

🙂

Duplicate detection functionality in CRM 2013

In CRM 2013, Duplicate record detection feature on create/update form has been removed due to the ‘Auto Save‘ functionality, which saves the form frequently.

Below are the 2 ways we can bring back the functionality.

Solution provided in CRM 2013 SDK 

  • In SDK there is a recommend approach to enable the duplicate detection feature on a required entity Create\Update form.
  • Download the CRM 2013 SDK, navigate toSDK\SampleCode\JS\DuplicateDetection\ReadMe.docx” document to get more information.
  • Here is an useful article with screen shots on the same.

Note –

  • We might need to disable your ‘autosave’, otherwise ‘autosave’ keeps triggering the duplicate detection
  • Refer this article how to skip autosave on onload or onsave.

CRM 2013 Duplicate Detection tool codeplex

  • There is a solution on codeplex which gives you the duplication detection functionality.
  • Download

🙂

New JScript syntaxes – CRM 2013

With the advent of CRM 2013, below are the new set of client API methods

CRM 2013 Client API

CRM 2013 Client API

Context

  • Xrm.Page.context.getUserName() Returns username of the currently logon user
  • Xrm.Page.context.getClient() Returns the client (i.e., Returns “Outlook”, “Web”, or “Mobile”)
  • Xrm.Page.context.client.getClientState()Returns  whether user is working online or offline.

Note – Xrm.Page.context.isOutlookOnline and isOutlookClient methods are deprecated

Data

  • Xrm.Page.data.refresh()Asynchronously refresh data on form without reloading the page
  • Xrm.Page.data.Save().then(successCallback, errorCallback) Allows you to save the record asynchronously with the option to set callback functions to be executed after the save operation is completed.
  • Xrm.Page.data.getIsValid() Validates the form and returns a Boolean.
  •  Xrm.Page.data.setFormDirty() – Allows to set IsDirty options on the form to (true/false).

Entity

  • Xrm.Page.data.entity.getPrimaryAttributeValue() Returns a string value of the primary attribute for the entity.

Xrm.Utility

  • Xrm.Utility.openWebResourceDialog(webResourceName,webResourceData,width,height) Displays html web resource as dialogs window.
  • Xrm.Utility.alertDialog(message,onCloseCallback) Displays alert box with a callback function.
  • Xrm.Utility.confirmDialog(message,yesCloseCallback,noCloseCallback) Displays confirm dialog with different callbacks depending on Yes/No button clicks.

 Set Notifications

  • Check this link for syntaxes

Number Fields

  •      Xrm.Page.ui.controls.get(controlName).setPrecision(2) – Overrides field’s precision

Date Fields

  •    Xrm.Page.ui.controls.get(controlName).setShowTime(true) Controls whether to show the time for a date field.
  •    Xrm.Page.ui.controls.get(controlName).setIsAllDay()Allows to set the date control to all day date time.

Look up Fields

  •    Xrm.Page.ui.controls.get(controlName).addCustomFilter(filter,entityLogicaName)
    •    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.ui.controls.get(controlName).addPreSearch(handler)Allows to add additional logic that will occur just before the search dialog box
  •   Xrm.Page.ui.controls.get(controlName).removePreSearch(handler)Removes event handler functions that previously been set in addPreSearch event.

🙂

Categories: CRM 2013 Tags: ,