Tuesday, May 31, 2016

Get the list of all properties of a class in C#

Hi,

Today we got a requirement to get the list of all the properties of a class including the values.

Here is a C# code for it.

class Customer
{
     public string FirstName { get; set; }
     public string LastName { get; set; }
     public string MiddleName { get; set; }
}

class Program
{
     static void Main(string[] args)
     {
         // Creating an object for a class
         Customer objCustomer = new Customer();
         objCustomer.FirstName = "John";
         objCustomer.LastName = "Hung";
         objCustomer.MiddleName = "Maro";

         // Reading the properties and displaying the Name and Value.
         foreach (var prop in objCustomer.GetType().GetProperties())
         {
             Console.WriteLine("{0} = {1}", prop.Name, prop.GetValue(objCustomer, null));
         }
         Console.Read();
      }
}

Hope this helps.

--
Happy Coding

Gopinath

Monday, May 30, 2016

Permissions of the User on a record - RetrievePrincipalAccessRequest in CRM 2001//2013/2015/2016


Hi,


Today we got a requirement what are the permissions of the user on a particular record. To fullfill this requirement, there is a SDK message called "RetrievePrincipalAccessRequest"


Here is the sample code of it.

RetrievePrincipalAccessRequest retrieveRequest = new RetrievePrincipalAccessRequest();
// record for which we want to check the access
retrieveRequest.Target = new EntityReference("opportunity", new Guid("A9F18D5F-6A08-E611-80DE-000D3AA03DA0"));
// User or Team entity Reference
retrieveRequest.Principal = new EntityReference("systemuser", new Guid("1C5A2AE8-AD00-E611-80DD-000D3AA03DA0"));
RetrievePrincipalAccessResponse retrieveResponse = (RetrievePrincipalAccessResponse)crmSerivce.Execute(retrieveRequest);


In the response we get the combination of all the rights either through sharing or his own security roles


Hope this helps.

--
Happy CRM'ing

Gopinath

Saturday, May 28, 2016

Retrieve Users/Teams who has access on the record

Hi,

Today, we got a requirement to retrieve list of users/Teams who has access on the record as part of business requirement.

SDK has a message to full fill this requirement. i.e RetrieveSharedPrincipalsAndAccessRequest

Here is the C# sample code for using it.


RetrieveSharedPrincipalsAndAccessRequest req = new RetrieveSharedPrincipalsAndAccessRequest();
req.Target = erfRecord;
RetrieveSharedPrincipalsAndAccessResponse resp = (RetrieveSharedPrincipalsAndAccessResponse)crmService.Execute(req);
foreach(PrincipalAccess prinAccess in resp.PrincipalAccesses)
{
     // prinAccess.AccessMask
     // prinAccess.Principal
}

AccessMask holds the access information
Principal holds the User/Team information.


--
Happy CRM'ing

Gopinath

Friday, April 22, 2016

The expected parameter has not been supplied for the report (Report render failure. Error: The 'CRM_CalendarType' parameter is missing a value)

Hi,
 
Today when we are trying to run the report for one of the user we are getting error saying
 
"The expected parameter has not been supplied for the report."

 
We did check in the Event Viewer and observed the below error message
 
"The expected parameter has not been supplied for the report."
 
I was pretty sure that there some thing we were missing as I was running OOB report.
 
The solution for this issue is very simple as the user does not have read permission for user settings , report not able to retrieve his calendar details (like Year format)
once assign read permission for User settings everything works fine.
 
  • Click Settings , click Administration , and then click Security Roles .
  • Double-click the security role that you use.
  • On the Business Management tab, set the Read privilege of the User Settings entity at least to the Business Unit level.
  • Click Save and Close.
 
Hope this helps.

--
Happy CRM'ing

Gopinath

Thursday, April 14, 2016

Close Opportunity as Lost in CRM 2011/2013/2015/2016

Hi,
 
Here is the code to close an Opportunity as Lost using the MS Dynamics CRM SDK.
 
In this example, I am using LoseOpportunityRequest to close an Opportunity as Lost.

public static void CloseOpportunityAsLose(IOrganizationService crmService, Guid guidOpportunityId)
{
      LoseOpportunityRequest req = new LoseOpportunityRequest();
      Entity opportunityClose = new Entity("opportunityclose");
      opportunityClose.Attributes.Add("opportunityid", new EntityReference("opportunity", guidOpportunityId));
      opportunityClose.Attributes.Add("subject", "Lost the Opportunity!");
      req.OpportunityClose = opportunityClose;
      OptionSetValue osvLostValue = new OptionSetValue();
      osvLostValue.Value = 4;
      req.Status = osvLostValue;
      LoseOpportunityResponse resp = (LoseOpportunityResponse)crmService.Execute(req);
}

Hope this helps.
 
--
Happy CRM'ing

Gopinath

 

Close Opportunity as Won in CRM 2011/2013/2015/2016

Hi,
 
Here is the code to close an Opportunity as Won using the MS Dynamics CRM SDK.
 
In this example, I am using WinOpportunityRequest to close an Opportunity as Won.

public static void CloseOpportunityAsWon(IOrganizationService crmService, Guid guidOpportunityId)
{
       WinOpportunityRequest req = new WinOpportunityRequest();
       Entity opportunityClose = new Entity("opportunityclose");
       opportunityClose.Attributes.Add("opportunityid", new EntityReference("opportunity", guidOpportunityId));
       opportunityClose.Attributes.Add("subject", "Won the Opportunity!");
       req.OpportunityClose = opportunityClose;
       OptionSetValue osvWon = new OptionSetValue();
       osvWon.Value = 3;
       req.Status = osvWon;
       WinOpportunityResponse resp = (WinOpportunityResponse)crmService.Execute(req);
}

Hope this helps.
 
--
Happy CRM'ing

Gopinath

 

Tuesday, April 12, 2016

C# Code for Removing Security Role to a User - CRM 2011/2013/2015/2016

Hi,

In the last post we have seen how to assign a security role to the user programmatically.

Here is the code for removing the security roles of the users.

public void RemoveUserSecurityRole(Guid guidSystemUserId, Guid guidSecurityRoleId, IOrganizationService crmService)
{
         // Create new Disassociate Request object for creating a N:N link between User and Security
         DisassociateRequest objDisassociateRequest = new DisassociateRequest();
         // Create related entity reference object for associating relationship
         // we will pass System User record reference of user for which the role is required to be removed 
         objDisassociateRequest.RelatedEntities = new EntityReferenceCollection();
         objDisassociateRequest.RelatedEntities.Add(new EntityReference("systemuser", guidSystemUserId));
        // Create new Relationship object for System User & Security Role entity schema and assigning it 
        // to request relationship property
        objDisassociateRequest.Relationship = new Relationship("systemuserroles_association");
        // Create target entity reference object for associating relationship
        objDisassociateRequest.Target = new EntityReference("role", guidSecurityRoleId);
        // Passing DisassociateRequest object to Crm Service Execute method for removing Security Role to User
        crmService.Execute(objDisassociateRequest);
}

Hope this helps.

--
Happy CRM'ing
Gopinath

C# Code for Assigning Security Role to a User - CRM 2011/2013/2015/2016

Hi,

Today we got a requirement to assign Security Role to a user. We all know that Security Roles are associated with User via N:N relationship and relationship name is systemuserroles_association.

We can use AssociateRequest to assign the security roles to the user programmatically.

Here is the C# code for assigning a security role to a user.

public void AssignSecurityRole(Guid guidSystemUserId, Guid guidSecurityRoleId, IOrganizationService crmService)
{
        // Create new Associate Request object for creating a N:N relationsip between User and Security
        AssociateRequest objAssociateRequest = new AssociateRequest();
        // Create related entity reference object for associating relationship
        // In this case we SystemUser entity reference  
        objAssociateRequest.RelatedEntities = new EntityReferenceCollection();
        objAssociateRequest.RelatedEntities.Add(new EntityReference("systemuser", guidSystemUserId));
        // Create new Relationship object for System User & Security Role entity schema and assigning it 
        // to request relationship property
        objAssociateRequest.Relationship = new Relationship("systemuserroles_association");
        // Create target entity reference object for associating relationship
        objAssociateRequest.Target = new EntityReference("role", guidSecurityRoleId);
        // Passing AssosiateRequest object to Crm Service Execute method for assigning Security Role to User
        crmService.Execute(objAssociateRequest);
}

Hope this helps.

--
Happy CRM'ing

Gopinath

Saturday, April 9, 2016

An attempt was made to load an assembly from a network location which would have caused the assembly to be sandboxed in previous versions of the .NET Framework

Hi,
 
Today we have deployed some of our .exe's and dlls on the server and when we ran the .exe we were getting the below exception.
 
"An attempt was made to load an assembly from a network location which would have caused the assembly to be sandboxed in previous versions of the .NET Framework"
 
I did check the .net versions and found all the things are absolutely fine. After sometime, came to know that the dll was blocked on the server.
 
To unblock the DLL or EXE,
 
Right click on DLL or EXE --> choose Properties --> click the Unblock button --> Apply and Ok.
 
The reason behind this blocking is normally operating system will blocks the DLL if it is copied from a network location because of security reasons.
 
Hope this helps.
 
--
Cheers,

Gopinath

Friday, April 8, 2016

Disable Send Report to Microsoft pop up - Microsoft Dynamics CRM has encountered an error

HI,

In CRM we get many error reports showing the below popup. We can hide this by changing a small setting in CRM.

Settings -> Administration -> Privacy Preferences -> Select Error Reporting and Select "Never send an error report to Microsoft"
 
 

Hope this helps.

--
Happy CRM'ing

Gopinath

Tuesday, March 22, 2016

Security Roles and Access Rights in CRM

Hi,
 
Security roles are the most complex concept in Dynamics CRM Security model. Here is my 2 cents about it.
 
Lets divide the security roles concepts into two pieces.
 
1) Privileges
Privileges are the basic units about an actions a user can perform on CRM. These actions predefined which cannot be added or delete but can be modified.
  • Create - Allows the user to add a new record.
  • Read - Allows the user to view a record.
  • Write - Allows the user to edit a record.
  • Delete - Allows the user to delete a record.
  • Append - Allows the user to attach other entities to, or associate other entities with a  parent record
  • Append to - Allows the user to attach other entities to, or associate other entities with the record.
  • Share - Allows the user to share a record with other Users/Teams.
2) Levels of Access
The Access Level determines, for a given entity, at which levels within the organization hierarchy a user can access.
  • None - No privileges given.
  • User - Privileges to the records owned by the user or shared with the user. Also includes the privileges owned by the team to which the user belongs.
  • Business Unit - Privileges for all records owned in the business unit to which the user belongs.
  • Parent: Child Business Unit - Privileges for all records owned in the business unit to which the user belongs and to all the child business units subordinate to that business unit.
  • Organization - Privileges for all records in the organization regardless of who owns.
Hope this helps.
 
--
Happy CRM'ing
Gopinath

Saturday, March 19, 2016

Move records automatically to Owner's Queue

Hi,

Today, we got a requirement from Customers to all the Tasks created in the system should move to the Owner's respective queue. Then we were thinking of the custom approach and then we got a doubt it should be available in OOB CRM with some configuration settings. After checking, yes it is available.

Go to Customizations -> Entity Information -> Tick the check box which is available just below the Queues as shown in the figure.

Hope this helps.
--
Happy CRM'ing

Gopinath

Wednesday, March 16, 2016

Export and Import Product Catalog in CRM

Hi,
 
CRM provides very easy and rich interface to configure Product Catalog that will help the company to sell products and services.
 
Most of the times, we would be creating Product Catalog in one system and wanted to move from one CRM to other CRM. After the Product Catalog is fully built and tested on one of the CRM systems, we can always export the complete catalog and import to other systems using Data Migration tool.
 
Here is the procedure of exporting and importing catalog from one CRM system to other.
 
1) Download SDK, Navigate to Tools-> Configuration Migration
2) Double click on DataMigrationUtility
3) Select Create Schema
4) Give CRM Credentials
5) Select the Organization where Product Catalog was properly configured
6) Select the Solution, the application will automatically gets all the entities in the solution and shows in the dropdown. Select Product entity and click on Add Entity button.
7) Select the below entities and click on Entity
  • Product
  • Product Association (needed for bundles)
  • Product Relationship (not a mandatory entity, needed only for relationships)
  • Property
  • Property Association
  • Property Option Set Item
  • Notes (needed, if there are any notes for the product)
  • Currency
  • Price List
  • Price List Item
  • Unit
  • Unit Group
  • Territory (needed if there is a default price list configuration)
  • Connection (needed, if there is a default price list configuration)
  • Competitor (needed, if there are any competitors for product)
  • Sales Literature and Sales Literature Item (needed, if there is any sales literature for product)
  • Discount (not a mandatory entity, needed only for discounts when added to price lists)
  • Discount List (not a mandatory entity, needed only for discounts)
8) click on Save and Export button

 9) Choose the location to save Schema
10) Click Yes on the Pop Up.
11) Select the location to save the Data file and click on Export Data button.
12) Now open the same tool again and select Import Data
13) Give the credentials and connect to organization where you want to copy the data.

14) Browse the Zip file which was created by the Export Process and click on Import Data.

Hope this helps.
 
--
Happy CRM'ing

Gopinath