Showing posts with label CRM 2011/2013/2015/2016. Show all posts
Showing posts with label CRM 2011/2013/2015/2016. Show all posts

Monday, 14 August 2017

Value cannot be null.\r\nParameter name: identityProvider

Hi,

Today I got the below error while running an console application which retrives account details from CRM.

Value cannot be null.\r\nParameter name: identityProvider

And that code was working earlier, not sure what went wrong and started searching here and there.

Finally, came to know that there was an extra space in the UserName which I have given as an input for the application to connect to CRM. Removed the space and able to perform my task.

Note : There could be many other reasons causing this issue and this wrong username or extra characters is one of them.

Hope this helps.

--
Happy CRM'ing
Gopinath

Saturday, 22 July 2017

Import Users to CRM

There are multiple ways to create new users in Dynamics CRM or Dynamics 365. We can use OOB import users as well.
Here are some of the key points which has to be followed via the Import Tool

1) For On Premise, User Name must have Domain name. Format - domain\user or user@domain.com format. For Online, Primary Email is mandatory
2) First Name and Last Name are mandatory.
3) All the users will be disabled in CRM.
4) We cannot set Business Unit during the import. By default, all users will be assigned to the Root business unit. After the import, we can update the business unit using Change Business Unit.
5) Every user will be assigned to Sales Person role by default.


Hope this helps.


--
Happy CRM'ing

Gopinath

Sunday, 27 November 2016

An Error has occurred. {1} {0} while importing to Solution to CRM

Hi
Today when I was importing the solution to CRM 2016 online received the below error.

An Error has Occurred. {1} {0}

Not sure what was the error as it didn't give me a chance to check the log.

The fix is to switch to other browser. I was using IE 11, switching to Chrome solved the issue.

Hope this helps.
--
Happy CRM'ing

Gopinath

Wednesday, 16 November 2016

Get the option set values of a field in an entity in Dynamics CRM using SDK and C# code

Hi,

Today we got a requirement to retrieve OptionSet values of a field from an entity in CRM. Here is the sample code of it.

public static OptionSetMetadata GetOptionSetsValuesInAnEntity(string entityName, string attributeName, IOrganizationService service)
{
       string AttributeName = attributeName;
       string EntityLogicalName = entityName;
       RetrieveEntityRequest retrieveDetails = new RetrieveEntityRequest
       {
             EntityFilters = EntityFilters.All,
             LogicalName = EntityLogicalName
       };
       RetrieveEntityResponse retrieveEntityResponseObj = (RetrieveEntityResponse)service.Execute(retrieveDetails);
       Microsoft.Xrm.Sdk.Metadata.EntityMetadata metadata = retrieveEntityResponseObj.EntityMetadata;
       Microsoft.Xrm.Sdk.Metadata.PicklistAttributeMetadata picklistMetadata = metadata.Attributes.FirstOrDefault(attribute => String.Equals(attribute.LogicalName, attributeName, StringComparison.OrdinalIgnoreCase)) as Microsoft.Xrm.Sdk.Metadata.PicklistAttributeMetadata;
       Microsoft.Xrm.Sdk.Metadata.OptionSetMetadata options = picklistMetadata.OptionSet;
      // Use below code to get the Option Set Item Name from Value (optionSetValue)
      //IList<Microsoft.Xrm.Sdk.Metadata.OptionMetadata> OptionsList = (from o in options.Options
      //                                     where o.Value.Value == optionSetValue
      //                                     select o).ToList();
      // string optionsetLabel = (OptionsList.First()).Label.UserLocalizedLabel.Label;
      return options;
}

Hope this helps.

--
Happy CRM'ing

Gopinath

Monday, 31 October 2016

Retrieve Statistics of Plugins/Workflow in Sandbox in Dynamics CRM

Hi,

CRM collects information about the plugins and custom workflows activities executing in Sandbox mode in PluginTypeStatistic records approximately every hour. The generated record produces information about the average execution time of each plugin and how many times it failed, killed or successfully executed.

Hope this helps.

--
Happy CRM'ing
Gopinath

Wednesday, 19 October 2016

Access fields in Header and Footer using JavaScript

Hi,

Most of times we get a requirement to access fields on Header and Footer using JavaScript.
There is a little difference in the schema to access them. That is we just need header/footer as a prefix to the field name. Below are the some of the examples.

Accessing Header Fields
//Set Enabled to True:
Xrm.Page.getControl("header_fieldname").setDisabled(false);
//Set Enabled to False:
Xrm.Page.getControl("header_fieldname").setDisabled(true);
//Set Visibility to False:
Xrm.Page.getControl("header_fieldname").setVisible(false);
//Set Visibility to True:
Xrm.Page.getControl("header_fieldname").setVisible(true);
//Get Attribute Value in Footer:
Xrm.Page.getControl("header_fieldname").getAttribute().getValue();
//Set Attribute Value in Footer:
Xrm.Page.getControl("header_fieldname").getAttribute().setValue("anything");

Accessing Footer Fields
//Set Visibility to False:
Xrm.Page.getControl("footer_fieldname").setVisible(false);
//Set Visibility to True:
Xrm.Page.getControl("footer_fieldname").setVisible(true);
//Get Attribute Value in Footer:
Xrm.Page.getControl("footer_fieldname").getAttribute().getValue();
//Set Attribute Value in Footer:
Xrm.Page.getControl("footer_fieldname").getAttribute().setValue("anything");


Hope this helps.

--
Happy CRM'ing

Gopinath

Tuesday, 27 September 2016

Qualify button is not working on Lead Entity

Hi,

Today we have faced a wierd issue where Qualify button is not working in Online CRM. It was a  vanilla crm with very few form layout changes. When we tried the same things with code, it was working fine.

After some search came to know that apparently the field Company Name is required for this process. Just placed back Company Name field on the form and unchecked Visible by default.


Hope this helps.
--
Happy CRM'ing,
Gopinath

Thursday, 21 July 2016

Check/Get user security role in CRM using C# Code

Hi,

Sometimes, we get the requirement to check the security role of the user in code and doing some business operation.

Here is the C# code for getting security role of the user.

QueryExpression queryExpression = new QueryExpression();
queryExpression.EntityName = "role"; //role entity name
ColumnSet cols = new ColumnSet();
cols.AddColumn("name"); //We only need role name
queryExpression.ColumnSet = cols;
ConditionExpression ce = new ConditionExpression();
ce.AttributeName = "systemuserid";
ce.Operator = ConditionOperator.Equal;
ce.Values.Add(userID);
//system roles
LinkEntity lnkEntityRole = new LinkEntity();
lnkEntityRole.LinkFromAttributeName = "roleid";
lnkEntityRole.LinkFromEntityName = "role"; //FROM
lnkEntityRole.LinkToEntityName = "systemuserroles";
lnkEntityRole.LinkToAttributeName = "roleid";
//system users
LinkEntity lnkEntitySystemusers = new LinkEntity();
lnkEntitySystemusers.LinkFromEntityName = "systemuserroles";
lnkEntitySystemusers.LinkFromAttributeName = "systemuserid";
lnkEntitySystemusers.LinkToEntityName = "systemuser";
lnkEntitySystemusers.LinkToAttributeName = "systemuserid";
lnkEntitySystemusers.LinkCriteria = new FilterExpression();
lnkEntitySystemusers.LinkCriteria.Conditions.Add(ce);
lnkEntityRole.LinkEntities.Add(lnkEntitySystemusers);
queryExpression.LinkEntities.Add(lnkEntityRole);
EntityCollection entColRoles = service.RetrieveMultiple(queryExpression);
if (entColRoles != null && entColRoles.Entities.Count > 0)
{
     foreach (Entity entRole in entColRoles.Entities)
     {
         if (entRole.Attributes["name"].ToString().ToLower() == "<Your rolename>")
         {
 
         }
     }
}

Hope this helps.

--
Happy CRM'ing
Gopinath

Wednesday, 20 July 2016

Associate/Disassociate plugin messages in CRM

Hi,

Most of the times to fulfill our requirement, we will creating N:N relation ship between the entities. Sometimes, we might need to perform some business logic which relating two records. For implementing we will have to write plugins and register them on "Associate" message.
 

Here is something interesting, the Associate and Disassociate messages behave little different that other messages.

When we register a plugin on Associate or Disassociate message, we have to leave Primary and Secondary entities as 'None'. As we haven't specified any entities, the plugin triggers on all Associate/Disassociate operations. We need to check few conditions to let the Association happen only between required entities.

Here is the sample which is like template for Associate/Disassociate message.

EntityReference targetEntity = null;
string strRelationshipName = string.Empty;
EntityReferenceCollection relatedEntities = null;
EntityReference relatedEntity = null;
if (pluginContext.MessageName == "Associate")
{
    // Get the "Relationship" Key from context
    if (pluginContext.InputParameters.Contains("Relationship"))
    {
        strRelationshipName = pluginContext.InputParameters["Relationship"].ToString();
    }
    // Check the "Relationship Name" with your intended one
    if (strRelationshipName != "<YOUR RELATION NAME>")
    {
         return;
    }
    // Get Entity 1 reference from "Target" Key from context
    if (pluginContext.InputParameters.Contains("Target") && pluginContext.InputParameters["Target"] is EntityReference)
    {
        targetEntity = (EntityReference)pluginContext.InputParameters["Target"];
    }
    // Get Entity 2 reference from "RelatedEntities" Key from context
    if (pluginContext.InputParameters.Contains("RelatedEntities") && pluginContext.InputParameters["RelatedEntities"] is EntityReferenceCollection)
    {
        relatedEntities = pluginContext.InputParameters["RelatedEntities"] as EntityReferenceCollection;
        relatedEntity = relatedEntities[0];
    }
}

Hope this helps.

--
Happy CRM'ing
Gopinath

Wednesday, 13 July 2016

Retrieve associated records (N:N related) in CRM

Hi,

In CRM, many times we create N:N relationship between 2 entities. When ever we do this, CRM internally creates an intermediate entity with 3 fields.

1) Primary key field of newly created entity.
2) First entity Primary Key field
3) Second entity Primary Key field


In my example, I have two entities called Books and Authors. One book can be written by multiple authors and one author can write multiple books.

Here is the code to retrieve Books written by Author 'Gopinath'

string strFirstEntity = "books";
string strSecondEntity = "authors";
string strRelationshipEntityName = "books_authors";
QueryExpression query = new QueryExpression(strFirstEntity);
query.ColumnSet = new ColumnSet(true);
LinkEntity linkEntity1 = new LinkEntity(strFirstEntity, strRelationshipEntityName, "books", "booksid", JoinOperator.Inner);
LinkEntity linkEntity2 = new LinkEntity(strRelationshipEntityName, strSecondEntity, "authors", "authorsid", JoinOperator.Inner);
linkEntity1.LinkEntities.Add(linkEntity2);
query.LinkEntities.Add(linkEntity1);
// Add condition to match the Author name with "Gopinath"
linkEntity2.LinkCriteria = new FilterExpression();
linkEntity2.LinkCriteria.AddCondition(new ConditionExpression("name", ConditionOperator.Equal, "Gopinath"));
EntityCollection collRecords = iService.RetrieveMultiple(query);

Hope this helps.

--
Happy CRM'ing

Gopinath

Monday, 30 May 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, 28 May 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, 22 April 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, 14 April 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