Archive
Get the view name of main grid using JScript
We got a requirement to Enable\disable ribbon button based on selected view.
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();
}
🙂
Auditing User’s Team membership in CRM
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.
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.
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 to “SDK\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
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.
🙂