Sunday, March 26, 2017

Dynamics 365 CRM Optimized QueryExpression snippet to retrieve data from 4 Down Hierarchal entities




Dynamics 365 CRM Optimized QueryExpression snippet to retrieve data from 4 Down Hierarchal entities



 
            QueryExpression userquery = new QueryExpression("systemuser");

            userquery.NoLock = true;

            userquery.Distinct = true;

            userquery.ColumnSet = new ColumnSet("systemuserid", "fullname");

            userquery.Criteria.AddCondition("isdisabled", ConditionOperator.Equal, false);

            LinkEntity elink = new LinkEntity("systemuser", "employee", "employee", "employeeid", JoinOperator.Inner);

            userquery.LinkEntities.Add(elink); 

            LinkEntity celink = new LinkEntity("employee", "connection", "employeeid", "record2id", JoinOperator.Inner);

            elink.LinkEntities.Add(celink);

 

            LinkEntity crlink = new LinkEntity("connection", "connectionrole", "record2roleid", "connectionroleid", JoinOperator.Inner);

            crlink.LinkCriteria.Conditions.Add(new ConditionExpression("category", ConditionOperator.Equal, 206490001));

            if(context.MessageName == "Assign" && context.PrimaryEntityName == "opportunity")

                crlink.LinkCriteria.Conditions.Add(new ConditionExpression("name", ConditionOperator.NotEqual, "OwnerName"));

            celink.LinkEntities.Add(crlink);

            celink.LinkCriteria.AddFilter(LogicalOperator.And);

            LinkEntity olink = new LinkEntity("connection", "opportunity", "record1id", "opportunityid", JoinOperator.Inner);

            olink.LinkCriteria.Conditions.Add(new ConditionExpression("opportunityid", ConditionOperator.Equal, _opptyid));//Pass OpportunityID Value

            celink.LinkEntities.Add(olink);

            var result = ImperService.RetrieveMultiple(userquery);

            foreach (var a in result.Entities)
            {
                if(!_userlist.Contains((Guid)a.Attributes["systemuserid"]))

                    _userlist.Add((Guid)a.Attributes["systemuserid"]);
            }

Advanced Security in Dynamics 365 CRM Using CRM SDK- Grant Access to User for a custom field(Encrypted – FLS enabled) to individual CRM records.



Advanced Security in Dynamics CRM Using CRM SDK- Grant Access to User for a custom field(Encrypted – FLS enabled) to a specific record.

In Dynamics CRM most of the time we assign Field Security profile to grant access to encrypted(FLS) fields which will provide access to the records that users have based on the security role. For certain scenarios we want to limit access to the users to only specific records (not all the records that they have access to) based on the business rule. Below is the snippet which grant access to users for individual CRM records:
if (CAattributeId == Guid.Empty)
                {
                    RetrieveAttributeRequest attrRequest = new RetrieveAttributeRequest()
                    {
                        EntityLogicalName = "opportunity",
                        LogicalName = "new_confidential",
                        RetrieveAsIfPublished = true
                    };
                    RetrieveAttributeResponse attrResponse = (RetrieveAttributeResponse)ImperService.Execute(attrRequest);
 
                    CAattributeId = attrResponse.AttributeMetadata.MetadataId.Value;
                }
                // Share the access
                Entity poaa = new Entity("principalobjectattributeaccess");
                poaa.Attributes.Add("attributeid", CAattributeId);
                poaa.Attributes.Add("objectid", new EntityReference("opportunity", Opptyid));
                poaa.Attributes.Add("principalid", new EntityReference("systemuser", userId));
                poaa.Attributes.Add("readaccess", true);
                poaa.Attributes.Add("updateaccess", false);
// updateaccess = true will allow users to update the field
 
ImperService.Create(poaa);
 


Tuesday, June 23, 2015

HOW TO: Integrate Custom web portal(ASPX) with CRM2015 ON-PREMISE Environment

Steps to Integrate Custom webportal on CRM2015 Default Port

  1. Create a Folder(Example: CustomImport) in CRMWeb Folder(Example: C:\Program Files\Microsoft Dynamics CRM\CRMWeb) and Copy/Paste all your files/website in it.
  2. Goto CRM Installation Path: CRMWeb\Help\bin (Example: C:\Program Files\Microsoft Dynamics CRM\CRMWeb\Help\bin) and copy all these files and paste it into the above website bin folder (where your Microsoft.Xrm.Sdk.dll located)
  3. Goto IIS drill down to the CRM Website and select the Folder which you have created in the Step1.
  4. Right Click on the Folder and click Convert to Application
  5. Verify Windows Authentication is enabled
If you notice any issues with custom webpage while accessing on HTTPS, perform below steps:
  • Run CRMAppPool under a Service Account which you are Impersonating the Custom WebPortal.
  • Ensure above Service Account is part of PrivUserGroup {GUID}
Note:  It is not a supported solution; However, it works like a charm and it doesn't impact any OOB solution.

Limitations of Dynamics CRM Database when Replicaiton(Transactional) is Enabled

1. Cannot Import Solution/Unable to make any customization changes

  • Includes Workflows/Plugin, etc
  • CRM Report changes
2. Cannot Import Data using Out of Box Data Import (mass data updates)

Note: Typically it gives SQL Server Error and you will not find any errors on CRM web server most of the time while performing above action.

Sunday, November 16, 2014

CRM 2015 New Features for CRM Developers

Improved Search Capabilities Improvements to quick search and make it faster and easier to find customer records on across the entities or different record types. Simply enter your search criteria in the general navigation search bar and let CRM do the searching for you.
The search results page will have an improved user interface. The search results will display based on the entity where the record is located, up to 8 multiple entities that were determined in the settings. If users want to only search one entity users can filter the search using the filter with drop-down


The enhanced search capabilities offer users a quick way to find and navigate to records by letting them enter keywords in the search box on the navigation bar. The search box supports using an asterisk (*) as a wild-card character

Hierarchy Visualization It provides business insights by visualizing hierarchically related data. This feature is designed to give you a hierarchical view into the data, enable you to navigate between records, select, open and edit records from the visualizations. You’ll be able to enable visuals for specific system entities and custom entities, after you have updated the hierarchy settings for the entity. The users can choose to view hierarchical data as charts, tiles or tree views. The hierarchy visuals defined in the Web application are also available in CRM for tablets, but modified to fit the smaller form factor. Because these visualizations are solution components, they can be transported between organizations like any other customizations. The visuals can be configured using the customization tools in the CRM Web application, not requiring to write code.


Enhanced Business Processes

CRM 2015 allows you to create branching rules and the ability to combine multiple conditions within a rule.
Enhanced Business Rules
CRM 2015 business rules can now contain If/Then logic and the ability to combine expressions using And/Or.

New operators in the Advanced Find The new operators are called ‘under’ and ‘Not Under’. These in some cases interact with new hierarchical security model in CRM 2015, and in other cases work with the hierarchy of accounts and other entities which have hierarchy model


Manage your configuration data
The configuration Migration tool enables you to move configuration data across CRM instances and organizations. Configuration data is used to define custom functionality in Microsoft Dynamics CRM, and is typically stored in custom entities. Configuration data is different from the end user data (account, contacts, and so on).
Configuration migration process flow diagram

Hierarchical Security Models

This will allow managers to access records for their direct reports based on Hierarchy across the organization. As a system administrator, this is going to be a huge time saver.


With the addition of the new security items, the Security has been moved to its own section in the navigation under SettingsHierarchical Security Models in Dynamics CRM 2015Security related items have been moved to security along with the new Hierarchy settings:
To enable the Hierarchy Security model select the Hierarchy Security item.Hierarchical Security Models in Dynamics CRM 2015
This will bring up the settings:
Calculated and Rollup attributes
Calculated and rollup attributes free the user from having to manually perform calculations and focus on their work. System administrators can now easily define a field to contain the value of many common calculations without having to work with a developer.