serving the solutions day and night

Pages

Showing posts with label dynamics 2011. Show all posts
Showing posts with label dynamics 2011. Show all posts

Wednesday, March 30, 2016

MS Dynamics CRM - Display Unique/Auto Number on the form before save.

My client requirement is display the unique reg number for new contact before the save record.
My Previous blog <a href="http://makdns.blogspot.com/2016/03/ms-dynamics-crm-generate-uniqueauto.html">MS Dynamics CRM - Generate Unique/Auto Number</a> will show the reg number on form after save the new contact. if the user clicks save and close, they can't see the number.

So i come up with the web service concept to generate unique number for new contact and display on the contact screen.
Also i am using SQL Server sys.sequences for generating new number.

Web Service Code

MS Dynamics CRM - Generate Unique/Auto Number

MS Dynamics CRM doesn't contain auto increment number attribute. My client was assigned each unique registration number for contact entity.
There is lot options available in the market, but i used very easy code to achieve this task. I used pre create plugin operation to create new registration unique/auto number. Number will be create on while saving the record.

i created one custom entity (dns_global), it will keep last reg number.

Dynamics CRM - Update Contact Fullname

My client want the fullname with the suffix and custom order like LastName, FirstName Middle Name Suffix. Dynamics CRM System Settings doesn't have the option to set the custom order fullname. Contact entity fullname is readonly attribute, it won't allow to update the fullname directly.

You can update through only pre create or update operation plugin.

Tuesday, March 29, 2016

MS Dynamics CRM - Login user's security role using javascript

I have one situation, login user has multiple security roles, if the login user has permission for particular role, show some buttons/fields otherwise the hide buttons/fields.

It is not stright forward to find out the security role, So i wrote one javascript to find out the security role.

Here i am checking the user has "Content Manager" security role or not.

var CMRole = CheckUserRole("Content Manager");
if (CMRole) {
    //true to show buttons
} else {
    //false to hide buttons
}


This function will get all the user's security role Id, passing security role id to get the security role name. If it match, it is true otherwise false.
function CheckUserRole(roleName) {
    var currentUserRoles = Xrm.Page.context.getUserRoles();
    for (var i = 0; i < currentUserRoles.length; i++) {
        var userRoleId = currentUserRoles[i];
         var userRoleName = GetRoleName(userRoleId);
         if (userRoleName == roleName) {
            return true;
         }
    }
    return false;
}


This function calling odata web service and get the each security role name.
 function GetRoleName(userRoleId) {
     var selectQuery = "RoleSet?$top=1&$filter=RoleId eq guid'" + userRoleId + "'&$select=Name";
     var odataSelect = GetServerUrl() + selectQuery;
     //alert(odataSelect);
     var roleName = null;
     $.ajax({
         type: "GET",
         async: false,
         contentType: "application/json; charset=utf-8",
         datatype: "json",
         url: odataSelect,
         beforeSend: function (XMLHttpRequest) { XMLHttpRequest.setRequestHeader("Accept", "application/json"); },
         success: function (data, textStatus, XmlHttpRequest) {
             var result = data.d;
             if (!!result) {
                 roleName = result.results[0].Name;
             }
         },
         error: function (XmlHttpRequest, textStatus, errorThrown) {
             //alert('OData Select Failed: ' + odataSelect);
         }
     });
     return roleName;
 }

Dynamics CRM - Get selected id from the grid and refresh.

1)Creates a custom button, contains one command (dns.dns_copies.Command.UnCopy)
2)command calling UnCopy javascript (library->$webresource:dns_js/Contact.js) function.
3)command contains 3 parameters
    i)[Crm Parameter]=SelectedControl   (grid name)
   ii)[Crm Parameter]=SelectedControlSelectedItemCount  (number of selected rows)
  iii)[Crm Parameter]=SelectedControlSelectedItemIds (selected entity ids)

Thursday, May 21, 2015

Dynamic CRM Hide/Show ribbon button by OnChange lookup field

1)create a javascript (HideShow.js), 2 functions

var HideShowButton = {
//refresh the ribbon when lookup field on change.
OnChangeLookup: function () {
        Xrm.Page.ui.refreshRibbon();
  },

//Show and Hide when form load
EnableCustomRule: function () {
if (Xrm.Page.data.entity.attributes.get("contactid") != null) {
   var contactId = Xrm.Page.data.entity.attributes.get("contactid").getValue()[0].id;
   var req = new XMLHttpRequest();
   var url = Xrm.Page.context.getClientUrl() + "/XRMServices/2011/OrganizationData.svc/ContactSet(guid'" + contactId + "')?$select=photoonfile";
   req.open("GET", encodeURI(url), false);
   req.setRequestHeader("Accept", "application/json");
   req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
   req.send();
   var data = JSON.parse(req.responseText).d;
   if (data.photoonfile == null || data.photoonfile == false) {
return true;
   }
   return false;
}
},
};

Thursday, June 12, 2014

Dynamic CRM 2011/2013 Audit Report in SSRS

My client want the particular contact entity attributes audit history in the horizontal way SSRS report.
CRM will create one line record in the audit entity for each action (new, update or delete records).
Refer "Dynamics CRM - Audit Entity" - http://makdns.blogspot.com/2014/06/dynamics-crm-audit-entity.html

1)Step created dynamics sql query

declare @contactid uniqueidentifier="00000000-0000-0000-0000-000000000000"> Declare @AuditTable table (id int identity(1,1), AuditId uniqueidentifier, ObjectTypeCode int, AttributeMask varchar(max) null,
        ChangeData varchar(max), CreatedOn datetime)
declare @AuditColumnResult table (id int identity(1,1), rid int null, AuditId uniqueidentifier, Increment int, ColumnKey int,
        ColumnName varchar(max), OldValue varchar(max), NewValue varchar(max), ObjectTypeCode int, createdon datetime)
declare @AuditHisoty table (AuditId uniqueidentifier, Increment int, ColumnKey int, ColumnName varchar(max), Value varchar(max))

Dynamics CRM - Audit Entity

AuditBase table or Audit entity are captured previous data of records.

CRM will create one line record in the audit entity for each action (new, update or delete records).

For example, First Name  Last Name
New Record -  FNC             LNC  => entity record
Old Record -  FN~LN             => audit stored, for example audit id 2, here first name new value is current entity record value  "FNC" and old value is current audit record "FN".
Old Record -  F~L             => audit stored, for example audit id 1, here first name new value is next audit record value  "FN" and old value is current audit record "F"

Wednesday, June 11, 2014

Convert Dynamics CRM Entity GUID in SSRS

When i create hyperlink i passed  GUID (Fields!contactid.Value) in the query string, the link is not working. I tried to convert GUID to string, still the link is not working.

Finally i used CType function to concatenation with the querystring, it works.

 = Parameters!CRM_URL.Value + "/tools/audit/audit_details.aspx?_CreateFromId=&_CreateFromType=2&id={" & CType(Fields!contactid.Value, GUID).ToString  & "}"

Tuesday, April 29, 2014

MS Dynamics CRM for Outlook Client - The server address (URL) is not a Microsoft Dynamics CRM Server

In Outlook Client, i clicked the Configure Microsoft Dynamics CRM for Outlook



i entered the server url, then press "Test Connection" button, i got the "Ther server address (URL) is not ac MS Dynamics CRM Server error. 



Tuesday, April 15, 2014

Migrating selected entities data from UAT MS Dynamics 2011 to PROD MS Dynamics CRM 2011

Migrating selected entities data from UAT MS Dynamics 2011 to PROD MS Dynamics CRM 2011

Recently i engaged a new project to migrating data from one CRM server to another CRM server for selected entities.
Challenging work is moving email related entity data to another CRM server.
Here i going to discuss only email related entity code work.

I did this work using both CRM service and direct sql update.

1) i created 2 service, let assume one is UAT and another is PROD
public static OrganizationServiceProxy U_CRMServiceProxy
{
    get
    {
    var uri = new Uri(U_URI);

    //Authenticate using credentials of the logged in user;      
    var cntCredentials = new ClientCredentials();
    cntCredentials.Windows.ClientCredential.Domain = Domain;
    cntCredentials.Windows.ClientCredential.UserName = U_User;
    cntCredentials.Windows.ClientCredential.Password = U_Pass;
    //cntCredentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials;

    var serviceProxy = new OrganizationServiceProxy(uri, null, cntCredentials, null);
    //serviceProxy.ServiceConfiguration.CurrentServiceEndpoint.Behaviors.Add(new ProxyTypesBehavior());
    serviceProxy.EnableProxyTypes();

    return serviceProxy;
    }
}

Dynamics CRM 2011 Activities Code & Configuration

Dynamics CRM 2011 Activities Code & Configuration

1.Activities Code

//Added Service Reference, reference name is 'ServiceEmailAudit'
//Code to Create Activities, this will get input field and call webservice
using System;
using System.Activities;
using System.ServiceModel;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Workflow;
using System.Linq;
using DNS.CRM.Entities;

namespace CRM.EmailAudit.Activities
{
    public class GenerateDAEmail : CodeActivity
    {
        [RequiredArgument]
        [Input("Report Name")]
        public InArgument<string> iReportName { get; set; }

Tuesday, April 1, 2014

MS Dynamics CRM 2011 E-mail Router Configuration

1) Go to MS Dynamics CRM 2011 E-mail Router -> select MS Dynamics CRM 2011 E-mail Router Configuration Manager

2) Configure Incoming and Outgoing profile

#9628 - An error occurred while delivering the e-mail message with subject

Application Event Log

#9628 - An error occurred while delivering the e-mail message with subject "Subject Line CRMDEV:00170032" in mailbox email@yahoo.com for delivery to http://crmserver.ses.com/DNS/. System.ServiceModel.FaultException`1[Microsoft.Xrm.Sdk.OrganizationServiceFault]: systemuser With Id = 03e6194a-c517-e211-b15b-0050568c5ad0 Does Not Exist (Fault Detail is equal to Microsoft.Xrm.Sdk.OrganizationServiceFault).

This error will be display, if any duplicate E-mail Address existed in CRM records.
If yes then delete that record and verify is the issue persist.

select * from EmailSearchBase where EMailAddress = 'email@yahoo.com'

It will list all the email assigned entities.

Take the 'ParentObjectTypeCode' id passed to the below sql.
select * from entityview where ObjectTypeCode in (1,8,10117,2020)

Now verify the record exist or not, if delete it.

for example, EmailSearchBase table record list, 8 is system user
EmailAddress    ParentObjectId                ParentObjectTypeCode
email@yahoo.com    03E6194A-C517-E211-B15B-0050568C5AD0    8

select * from systemuser where systemuserid  = '03E6194A-C517-E211-B15B-0050568C5AD0'
there is no record in system user.

so i delete the entry from EmailSearchBase table.

Everything works perfectly, all the error stops.

Wednesday, September 11, 2013

MS Dynamics CRM Web Services 2011

MS Dynamics CRM 2011 provides two Web services. These services can be used to identify your organization and to access MS Dynamics CRM data.

IDiscoveryService Web Service - A single MS Dynamics CRM installation can host multiple organizations on multiple servers. The IDiscoveryService Web service returns a list of organizations that the specified user belongs to and the URL endpoint address for each organization.
http[s]://< hostname[:port]>/XRMServices/2011/Discovery.svc

To access the IDiscoveryService Web service, use Microsoft.Xrm.Sdk.dll assembly -> Microsoft.Xrm.Sdk.Discovery namespace.
Use the Execute method to execute a discovery service message.
RetrieveOrganizationRequest - Retrieves information about a single organization.
RetrieveOrganizationsRequest - Retrieves information about all organizations to which the user belongs.
RetrieveOrganizationsResponse

IOrganizationService Web Service - The Web service for accessing data and metadata in MS Dynamics CRM 2011
Organization Service Methods - Create, Retrieve, RetrieveMultiple, Update, Delete, Associate ( create a link between two records), Disassociate, Execute

IOrganizationService Entities

Best Practices for Developing with Microsoft Dynamics CRM

Tuesday, September 10, 2013

Programming Models for MS Dynamics CRM 2011


Key programmability scenarios for MS Dynamics CRM 2011



Early-bound – MS Dynamics CRM 2011 uses an entity data model and Windows Communication Foundation (WCF) Data Services technologies to provide a new set of tools that interact with Microsoft Dynamics CRM. For example: an organization service context that tracks changes to objects and supports .NET Language-Integrated Query (LINQ) queries to retrieve data from MS Dynamics CRM. Early bound classes generated directly from the metadata, which include all customizations.
CrmSvcUtil.exe - CRM Dynamics 2011 Code Generation Tool

Improve PrincipalObjectAccess (POA) and AsyncoperationBase table performance in MS Dynamics CRM 2011

PrincipalObjectAccess (POA) table

Grant permission for a user to see/edit/delete a record in CRM.

Permissions are granted is through either Direct or Inherited shares. 

Direct Shares are the user shares a record to another user or team through the 'share' button in the ribbon. These records will have a value in the AccessRightsMask colum of the POA table.

Inherited Shares are the result of a number of different configuration rules – such as the shares that cascade to an object based on the ownership of its parent record, Custom code that shares a record, or by the system due to relationship behaviors or system settings. These records will have a value in the InheritedAccessRightsMask colum of the POA table.

The shares granted on objects in CRM are stored in the PrincipalObjectAccess (POA) system table. Since almost every access to CRM data interacts with the POA table.

Friday, September 6, 2013

MS Dynamics CRM 2011 - Display Lists/Views Dynamically

Audit_matchlist.htm - HTML Page Code

This page will build fetchxml, display event list from event entity, matchtype option set, and bind the result in the frame.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta content="text/html;charset=utf-8" http-equiv="Content-Type"/>
    <meta content="utf-8" http-equiv="encoding"/>
    <meta http-equiv="X-UA-Compatible" content="IE=EDGE" />
    <meta http-equiv="CACHE-CONTROL" content="NO-CACHE"/>
    <link href="/WebResources/dns_CSS/audit.css" rel="Stylesheet" />

    <script src="../ClientGlobalContext.js.aspx" type="text/javascript"></script>
    <script src="/WebResources/dns_JavaScript/Jquery1.4.1.min.js" type="text/javascript" language="javascript"></script>
    <script src="/WebResources/dns_JavaScript/Jason.js" type="text/javascript" language="javascript"></script>
    <script src="/WebResources/dns_JavaScript/advancedfindview.js" type="text/javascript" language="javascript"></script>
    <script src="/WebResources/dns_JavaScript/DataOperations.js" type="text/javascript" language="javascript"></script>
    <script src="/WebResources/dns_JavaScript/audit.js" type="text/javascript" language="javascript"></script>
    <script type="text/javascript">
        var ECMRole = CheckUserRole("ECM");
       
        //alert(window.location.href);