Friday, 28 February 2014

Plugins Vs Real time workflows

Interesting Piece on plugins vs Real time workflows workflows


The performance of workflows is still considered slow , so too many of them , or workflows on a system with a high degree of concurrency is considered bad practice

Also configuration control (via system parameters for example)  of workflows  can be problematic 

Wednesday, 26 February 2014

Filter lookups based on fetch XML CRM 2011/CRM2013

BElow is an example of how to filter a lookup on a form by Fetch XML. This can be usefull when you need to filter by more than one condition or a very custom  conditions

function preFilterLookup() {    Xrm.Page.getControl("parentaccountid").addPreSearch(function () {
     addLookupFilter();
     addLookupFilter();   });}function addLookupFilter() {
    
    var email = Xrm.Page.getAttribute("emailaddress1").getValue();    if (email != null) {
        fetchXml = 
        fetchXml = "<filter type='and'><condition attribute='emailaddress1' operator='eq' value='" + email + "' /></filter>";            Xrm.Page.getControl("parentaccountid").addCustomFilter(fetchXml);
    }
}
    }}

THe preFilterLookup() function needs to be called from the onload

Team access to Records

A user can be given access to record that he/she doesn't own via Team even though they only have only have user privileges on that record type

To accomplish this the record is assigned to The team

The user has to be assigned to a Team.
If the user has user access to the contact record:




And he/She is part of the team the contact was assigned to (test Team) then he now also has access to the record

Assign User to a team queue
This can be particularly useful when Giving users access to queues.
The use can have user access on queues
The system queue can be assigned to a team
The user is then assigned to a team






Guide on how to check a users Security Roles in 2011/2013 javascript

Helpfull Guide Outlined here
http://lakshmanindian.wordpress.com/2012/05/23/check-user-security-role-in-crm-2011-using-jscript/

Pasted  :
Check User Security Role in CRM 2011
Sometimes we get a requirement to check user security role and based on the result we need to perform certain operations. Here is the CRM 2011 Jscript code to check whether the user has a particular role or not.
We need to add “jquery1.4.1.min”(or laest version available) and “json2″ in the entity form, to perform a ODATA call as shown below. You can get those two files from the sdk.
Path – \sdk\samplecode\js\restendpoint\jqueryrestdataoperations\jqueryrestdataoperations\scripts
The Following code checks whether the “Activity Feeds” security role exists for the user or not and gets alert with true or false on onload jscript event. The functions CheckUserRole and FetchUserRoleIdWithName can be put in a sepertate js webresource it can be used across many entities
function onload(){
   // returns true if the given security role exists for the user, else returns false
   alert(CheckUserRole("Activity Feeds", Xrm.Page.context));
}

// This method takes SecurityRole Name and context as parameters
function CheckUserRole(roleName, context) {
   var userHasRole = false;

   //get the current roles for the user
   var userRoles = context.getUserRoles();

   //get the roleids with the rolename
   //the roleids can be multiple for multiple business units
   var roleIdArray = FetchUserRoleIdWithName(roleName, context);
   for (var userRole in userRoles) {
      if (jQuery.inArray(userRoles[userRole], roleIdArray) != -1){
         userHasRole = true;
         break;
      }
   }
   return userHasRole;
}

// Checks whether the security role exists in the system by using ODATA call
function FetchUserRoleIdWithName(roleName, context) {
   var serverUrl = Xrm.Page.context.getServerUrl();
   var oDataUri = serverUrl +  "/XRMServices/2011/OrganizationData.svc/RoleSet?$filter=Name eq '" + roleName + "'&$select=RoleId";
   var jSonArray = new Array();

   jQuery.ajax({
      type: "GET",
      contentType: "application/json; charset=utf-8",
      datatype: "json",
      url: oDataUri,
      async: false,
      beforeSend: function (XMLHttpRequest) {
         //Specifying this header ensures that the results will be returned as JSON.
         XMLHttpRequest.setRequestHeader("Accept", "application/json");
      },
      success: function (data, textStatus, XmlHttpRequest) {
         if(data && data.d != null){
            for(var count =0; count < data.d.results.length; count++){
               jSonArray.push(data.d.results[count].RoleId);
            }
         }
      },
      error: function (XmlHttpRequest, textStatus, errorThrown) {
         alert("Error :  has occured during retrieval of the role " + roleName);
      }
   });
   return jSonArray;
}

Tuesday, 25 February 2014

Enabling Duplicate Detection On CRM 2013 or CRM Rollup 12

Statement from Microsoft:
Duplicate detection during create and update operations will not be supported for Microsoft Dynamics CRM updated user interface entities. Duplicate detection of individual records won’t be supported for custom entities as well. However, to detect duplicates in bulk, you can use the ‘BulkDetectDuplicatesRequest’ message and the ‘RetrieveDuplicatesRequest’ message….
It has also been disabled for The refreshed forms on 2011 roll-up 12(Polaris)

Fortunitly Jason Lattimer has devised a solution to this problem.
https://crm2103dupedetect.codeplex.com/


Installation Instructions:
1. Download the Package from  https://crm2103dupedetect.codeplex.com/releases/view/118399 and import it into CRM.
2. On the entity form you need to attach the following js files
  • lat_/CRM2013DuplicateDetection/scripts/SDK.Metadata.Query.min.js
  • lat_/CRM2013DuplicateDetection/scripts/Xrm.DupDetect.js
3. In the Event handlers Add the following to the onload event
Xrm.DupDetect.config [lat_/CRM2013DuplicateDetection/scripts/Xrm.DupDetect.js]

4. In the Parameters Put The following
   [ {"preventsaveduplicate": false} ]
Setting "preventsaveduplicate" to true will prevent records from being saved if a potential duplicate is returned

It Should look like this :


What it looks Like:



Microsoft CRM Create Request Using Duplicate Detection Rules

The Following is an example on how to fire Duplicate Detection Rules when using the CreateRequest/UpdatieRequest Records via

SuppressDuplicateDetection
The Key Property here is "SuppressDuplicateDetection"
If you set "SuppressDuplicateDetection" to False duplicate detection will run. If you set it to True an exception with the below message will be thrown if a Duplicate is found

"A record was not created or updated because a duplicate of the current record already exists"

False Is the Default

Example


 //AccountAccount account = new Account
{
Name = "Proseware, Inc.",
AccountNumber = "ACC005"
};
//Here is an Example on How to create a record wth duplicate detection turned off. // Create operation by suppressing duplicate detectionCreateRequest reqCreate = new CreateRequest();
reqCreate.Target = account;
reqCreate.Parameters.Add("SuppressDuplicateDetection", true);
CreateResponse createResponse = (CreateResponse)_service.Execute(reqCreate);
Guid _dupAccountId = createResponse.id;
 //Account will create because duplicate detection is truned off 

//Here is an Example on How to create a record wth duplicate detection turned ON. // Create operation by suppressing duplicate detectionCreateRequest reqCreate = new CreateRequest();
reqCreate.Target = account;
reqCreate.Parameters.Add("SuppressDuplicateDetection", false);
try{CreateResponse createResponse = (CreateResponse)_service.Execute(reqCreate);
_dupAccountId = createResponse.id;
 //Account will create if no duplicate }
catch (FaultException<OrganizationServiceFault> ex){
if (ex.Detail.ErrorCode == -2147220685){
// duplicate detected: Handle it here}
else{
throw;
}




The same can be done via the UpdateRequest when updating a record