Wednesday, March 9, 2016

Set Default Dashoard MSCRM C#

Hi,

Please find the code below for setting Default Dashboard while Associating Role to Particular User





EntityCollection loaddashboards = GetDashboardGuid(dashboardname);
Entity roles = new Entity("usersettings");
roles.Attributes["systemuserid"] = UserID;
roles.Attributes["defaultdashboardid"] = loaddashboards.Entities[0].Attributes["formid"];
orgService.Update(roles);


private EntityCollection GetDashboardGuid(string name)
        {
            QueryExpression qry = new QueryExpression("systemform");
            qry.ColumnSet.AddColumns("name", "formid");
            qry.Criteria.AddCondition(new ConditionExpression("name", ConditionOperator.Equal, name));
            EntityCollection loaddashboards = orgService.RetrieveMultiple(qry);
            return loaddashboards;
        }

Friday, March 4, 2016

What's New Permission Issue

Hi,

If what’s new shows error likeYou do not have permissions to see this view. Contact a system administrator.

For fixing the issue, we need to give privileges on1) At least User level Read rights on Filter 2) Organization level Read rights on Post Configuration




Create Access Teams in c#

Hi,


Create Access Team Template based on c# code.


Entity teamtemplate = new Entity("teamtemplate");
teamtemplate.Attributes["teamtemplatename"] = TeamName;
teamtemplate.Attributes["teamtemplateid"] = TeamGuid;
teamtemplate.Attributes["defaultaccessrightsmask"] = Convert.ToInt32(accessRights);
teamtemplate.Attributes["objecttypecode"] = typecode;

orgService.Create(teamtemplate);

Deactivate CRM Forms

Hi,

Deactivate CRM Forms.

Create an XML File and name it as SystemForm

XML FILE:

Pass formname and Objecttypecode in seperation of Comma

<?xml version="1.0" encoding="utf-8" ?>
<systemform>
  <form>account,1</form>
  <form>contact,2</form>
  <form>campaign,4400</form>
  <form>Campaign Activity,4402</form>
  <form>Contract,1010</form>
  <form>Contract Detail,1011</form>
  <form>Email,4202</form>
  <form>Appointment,4201</form>
  <form>Wizard,4201</form>
  <form>Email Server Profile,9605</form>
  <form>Fax,4204</form>
  <form>letter,4207</form>
  <form>Phone Call,4210</form>
  <form>Team,9</form>
  <form>Task,4212</form>
  <form>Sales Literature,1038</form>
  <form>Wizard,4202</form>
  <form>User,8</form>
  </systemform>


C# Code: 

var appSettings = ConfigurationSettings.AppSettings;
                XmlDocument systemform = new XmlDocument();
                systemform.Load(@"SystemForm.xml");
                int n;

                foreach (XmlNode node in systemform.DocumentElement.ChildNodes)
                {
                    string[] formnode = node.InnerText.Split(',');
                    bool isNumeric = int.TryParse(formnode[1], out n);
                    if (isNumeric)
                    {
                        QueryExpression deactivateForms = new QueryExpression(appSettings["EntityForms"]);
                        deactivateForms.ColumnSet = new ColumnSet(true);
                        deactivateForms.Criteria.AddCondition(new ConditionExpression(appSettings["FormName"], ConditionOperator.Equal, formnode[0].ToString()));
                        deactivateForms.Criteria.AddCondition(new ConditionExpression(appSettings["FormAttribute"], ConditionOperator.Equal, Convert.ToInt32(formnode[1].ToString()))); // Entity Object type code               
                        EntityCollection getDeactivatedfroms = orgService.RetrieveMultiple(deactivateForms);
                        foreach (Entity finaldeactivation in getDeactivatedfroms.Entities)
                        {
                            Entity newentity = new Entity(appSettings["EntityForms"]);
                            newentity[appSettings["FormAttribute"]] = finaldeactivation.Attributes[appSettings["FormAttribute"]];
                            newentity[appSettings["FormActivationState"]] = new OptionSetValue(Int32.Parse(appSettings["FormInActive"]));
                            newentity[appSettings["FormId"]] = finaldeactivation.Attributes[appSettings["FormId"]];
                            orgService.Update(newentity);
                        }
                    }
                    else
                    {
                        MessageBox.Show(formnode[1] + "is not Valid For Form Deactivation");

                    }

User belongs to Different Business Unit than a Role

Hi,
Today I got a scenario to create a User and assign Security Role to a User.
While associating Role to the Team am getting following error
“User belongs to Different Business Unit than a Role”

Resolution:

After creating user check the Business Unit of the User and Pass the Business Unit to the Query Expression and the Result of Role associate to the User

QueryExpression role = new QueryExpression("role") { ColumnSet = new ColumnSet(true) };
                    role.Criteria.AddCondition(new ConditionExpression("name", ConditionOperator.Equal, "Activity Feeds"));
                    role.Criteria.AddCondition(new ConditionExpression("businessunitid", ConditionOperator.Equal, businessunitid));
                    EntityCollection roleActivity = orgService.RetrieveMultiple(role);


Thursday, February 18, 2016

Impersonate the Plugins MSCRM C#

Hi,

Today i have a scinario to impersonate the plugin for that we followed below steps.

Open Plugin Registration tool and open the plugin which you need to impersonate. Pass the GUID in Unsecure Configuration


Once Done. Update the step and 

public Impersonate(string unsecure)
            : base(typeof(Impersonate))
        {
            base.RegisteredEvents.Add(new Tuple<int, string, string, Action<LocalPluginContext>>(40, "Update", "ENTITYNAME",
                new Action<LocalPluginContext>(ExecuteImpersonate)));
            if (!Guid.TryParse(unsecure, out ssisUserGuid))
            {
                throw new InvalidPluginExecutionException(CustomMessagesResources.Error_PostCustomerAssign_ConfigRead);
            }

        }
 protected void ExecutePostCrmDealUpdateSecurity(LocalPluginContext localContext)

        {
 EntityReference callingUser = new EntityReference
                        {
                            LogicalName = "systemuser",
                            Id = ssisUserGuid
                        };
                        OrganizationServiceProxy serviceProxy = (OrganizationServiceProxy)service;

                        serviceProxy.CallerId = callingUser.Id;
}

The above code will impersonate the plugin to the user which you have mentioned in the plugin unsecure configuration.

Async Privilage is Missing for the User

if User is getting Async privilage Error while running the Plugin 
as Principal user (Id=GUID, type=8) is missing prvReadAsyncOperation privilege

Go to Security Roles --> Customization -->Provide privilage for System Jobs


Day 11 - Customizing Option Sets Dropdown Fields with JavaScript

  In this Blog, we will see how to Customizing Option Sets Dropdown Fields with JavaScript label1 = formContext.getAttribute( "bosch_op...