Sample code for adding a custom button on a custom tab for SubGrid of an entity in ribbon (CRM 2011)


Just replace the schema name of your entity.

 <RibbonDiffXml>
        <CustomActions>
          <CustomAction Id="Sample.SubGrid.entitySchemaName.CustomTab.CustomAction" Location="Mscrm.SubGrid.entitySchemaName.ContextualTabs._children" Sequence="40">
            <CommandUIDefinition>
              <Tab Id="Sample.SubGrid.entitySchemaName.CustomTab" Command="Sample.SubGrid.entitySchemaName.CustomTab" Title="Custom Tab" Description="Custom Tab Description" Sequence="500">
                <Scaling Id="Sample.SubGrid.entitySchemaName.CustomTab.Scaling">
                  <MaxSize Id="Sample.SubGrid.entitySchemaName.CustomTab.FirstGroup.MaxSize" GroupId="Sample.SubGrid.entitySchemaName.CustomTab.FirstGroup" Sequence="10" Size="LargeMedium" />
                </Scaling>
                <Groups Id="Sample.SubGrid.entitySchemaName.CustomTab.Groups">
                  <Group Id="Sample.SubGrid.entitySchemaName.CustomTab.FirstGroup" Command="Sample.SubGrid.entitySchemaName.FirstGroup" Sequence="10" Title="Custom First Group" Template="Mscrm.Templates.3.3">
                    <Controls Id="Sample.SubGrid.entitySchemaName.CustomTab.FirstGroup.Controls">
                      <Button Id="Sample.SubGrid.entitySchemaName.CustomTab.FirstGroup.FirstButton" ToolTipTitle="ButtonToolTipTitle" ToolTipDescription="ToolTipDescription" Command="Sample.SubGrid.entitySchemaName.FirstButton" Sequence="10" LabelText="LabelText" Alt="LabelText" Image16by16="/_imgs/ribbon/AddEmail_16.png" Image32by32="/_imgs/ribbon/Email_32.png" TemplateAlias="o1" />
                    </Controls>
                  </Group>
                </Groups>
              </Tab>
            </CommandUIDefinition>
          </CustomAction>
        </CustomActions>
        <Templates>
          <RibbonTemplates Id="Mscrm.Templates"></RibbonTemplates>
        </Templates>
        <CommandDefinitions>
          <CommandDefinition Id="Sample.SubGrid.entitySchemaName.FirstGroup">
            <EnableRules>
              <EnableRule Id="Mscrm.Enabled " />
            </EnableRules>
            <DisplayRules>
            </DisplayRules>
            <Actions />
          </CommandDefinition>
          <CommandDefinition Id="Sample.SubGrid.entitySchemaName.CustomTab">
            <EnableRules>
              <EnableRule Id="Mscrm.Enabled " />
            </EnableRules>
            <DisplayRules>
            </DisplayRules>
            <Actions />
          </CommandDefinition>
          <CommandDefinition Id="Sample.SubGrid.entitySchemaName.FirstButton">
            <EnableRules />
            <DisplayRules />
            <Actions>
              <JavaScriptFunction Library="$webresource:new_test" FunctionName="showvalue">
                <StringParameter Value="Guid(s) Selected" > </StringParameter>
                <CrmParameter Value="SelectedControlSelectedItemIds"></CrmParameter>
              </JavaScriptFunction>
            </Actions>
          </CommandDefinition>
        </CommandDefinitions>
        <RuleDefinitions>
          <TabDisplayRules>
            <TabDisplayRule TabCommand="Sample.SubGrid.entitySchemaName.CustomTab">
              <EntityRule EntityName="entitySchemaName" Context="SubGridStandard" />
              <EntityRule EntityName="entitySchemaName" Context="SubGridAssociated" />
            </TabDisplayRule>
            <TabDisplayRule TabCommand="Sample.Form.entitySchemaName.CustomTab">
              <EntityRule EntityName="entitySchemaName" Context="Form" AppliesTo="PrimaryEntity" />
            </TabDisplayRule>
            <TabDisplayRule TabCommand="Sample.Grid.entitySchemaName.CustomTab">
              <EntityRule EntityName="entitySchemaName" Context="HomePageGrid" />
            </TabDisplayRule>
          </TabDisplayRules>
          <DisplayRules />
          <EnableRules />
        </RuleDefinitions>
        <LocLabels />
      </RibbonDiffXml>

This is the helpful post

http://dynamicscrm2011.wordpress.com/tag/adding-a-button-to-the-crm-2011-sub-grid-ribbon/

Hope it helps !

Using List control to show 1 to n related information in a repeated manner in SSRS report.


 

Suppose these are our two tables, Person and Person Details, having one to many relationships to each other.

Person:-

Person details:-

Now here we would like the report to show data in the following format (in repeated fashion)

1st record of Person Table

All details of that record

2nd record of Person Table

All details of that record

Now first create a report having following simple query for the data set

SELECT Id, [First Name], [Last Name], Email FROM Person

Now create one more report which we would be using as a Subreport with the following query

SELECT Hobby FROM [Person Details] WHERE (Id = @Id)

Now go to our main report,

Add a List Control to the report.

Drag the fields from the DataSet of the main Person table to the report.

Next drag the Subreport control inside the list control of the report.

Specify properties for the Subreport.

Refer to my previous post for that (little lazy to put those stuffs again)

https://nishantrana.wordpress.com/2011/08/20/using-subreport-control-to-show-1-to-n-related-information-in-ssrs-report/

Our final report would look like this.

Hope it is helpful.

Using Subreport control to show 1 to n related information in SSRS report.


Suppose these are our two tables, Person and Person Details, having one to many relationships to each other.

Person:-

Person details:-

Now first create a report having following simple query for the data set

SELECT Id, [First Name], [Last Name], Email FROM Person

Now create one more report which we would be using as a Subreport with the following query

SELECT Hobby FROM [Person Details] WHERE (Id = @Id)

Now go to our main report, select id column, right click it and select add column to the right.

Drag Subreport control from the toolbox there in the new column added

Next right click it and select Subreport properties

Specify the detail report as Subreport.

For visibility specify the following options (report would be auto expanded and we will have + sign in front of our id column through which we can toggle the visibility of the subreport)

For Parameters specify value for the id to be passed from the main report.

That’s it. We are done J

Hope it is helpful.

Working with SharePointDocumentLocation in CRM 2011.


We had a requirement to associate a SharePointDocumentLocation with a case record when it is created. We wanted to use our own folder structure for it. Something similar to this

Sharepointdocumentlibraryurl/[CustomerName]/[CaseNumber]

i.e. folder name with Customer Name and a subfolder with the name of Case Number.

Normally SharePoint document location is created when we click on Documents on the left navigation pane for the record. It doesn’t get created or auto associated to a SharePoint folder on create of record.

So the solution was to write a plugin in on create event and then create a folder in SharePoint and then associate it with the created record.

The source code for implementing it (just posting the source code i hope it is self explanatory 🙂 )


// following logic within the Post Create plugin of Case (incident)
	 if (this.Context.MessageName.ToUpper() == "CREATE" && Context.InputParameters.Contains("Target")
                && Context.InputParameters["Target"] is Entity)
            {
                Entity targetIncident = (Entity)Context.InputParameters["Target"];

                //// Create doc folder for case
                Guid incidentId = Context.PrimaryEntityId;
                string ticketNumber = targetIncident["ticketnumber"].ToString();
                Guid customerId = ((EntityReference)targetIncident["customerid"]).Id;

                Contact contact = // code to get the contact's fullname

                SharePointHelper sharepoint = new SharePointHelper();
                sharepoint.CreateFolderForCase(organizationService, contact.FullName, ticketNumber, incidentId);
            }

// Helper functions used

	    public string CreateFolderForCase(OrganizationService coreCrmService, string contacFolderName, string caseFolderName, Guid incidentId)
        {
            string docLibraryUrl = "http://SharePointSiteCollection/incident";
            string applicantFolderUrl = docLibraryUrl + "/" + applicantFolderName;
            string caseUrl = applicantFolderUrl + "/" + caseFolderName;

            //// Create folder and subfolder inside SharePoint site
            this.CreateFolderStructure(applicantFolderUrl, caseUrl);

            //// create and associate the url of the folder to SharePointDocumentLocation and the incident record.
            this.CreateAndAssociateSharePointDocumentLocation(coreCrmService, incidentId, caseFolderName, caseUrl);
            return caseUrl;
        }

		private bool CreateFolderStructure(string applicantFolderUrl, string caseFolderUrl)
        {
            if (this.CreateFolder(applicantFolderUrl))
            {
                return this.CreateFolder(caseFolderUrl);
            }

            return false;
        }

		private bool CreateFolder(string folderUrl)
        {
            try
            {
                WebRequest request = WebRequest.Create(folderUrl);
                request.Credentials = this.credentials;
                request.Method = "MKCOL";
                WebResponse response = request.GetResponse();
                response.Close();
            }
            catch(Exception ex)
            {
                TraceHelper.TraceEvent(ex, "CreateFolder", folderUrl, TraceHelper.AMSApplication.AMSService);
            }
            return true;
        }

		public static bool CreateAndAssociateSharePointDocumentLocation(OrganizationService coreCrmService, Guid incidentId, string caseNumber, string sharePointDocumentUrl)
        {
            SharePointDocumentLocation sharePointDocumentLocation = new SharePointDocumentLocation();
            sharePointDocumentLocation.Name = "SharePoint Document Location for " + caseNumber;
            sharePointDocumentLocation.Description = "SharePoint Document Location created for storing documents related to case";
            sharePointDocumentLocation.AbsoluteURL = sharePointDocumentUrl;
            sharePointDocumentLocation.RegardingObjectId = new EntityReference("incident", incidentId);
			coreCrmService.Create(sharePointDocumentLocation);
            return true;
        }

Please refer these wonderful posts that were extremely helpful.

http://charlesemes.blogspot.com/2011/02/create-sharepoint-document-locations-in.html

http://geek.hubkey.com/2007/10/upload-file-to-sharepoint-document.html

Export SSRS report as a proper PDF file


After we have created a report in SSRS, if we try to export it in PDF, we could find that our report might not be properly getting rendered in PDF. Instead of fitting in a single page, some part of the report may show up as a second page of the PDF.

These are things we need to keep in mind if we want to render our report properly in a single page

1. Click on Report > Report Properties > Layout tab
2. Make a note of the values for Page width, Left margin, Right margin
3. Close and go back to the design surface
4. In the Properties window, select Body
5. Click the + symbol to expand the Size node
6. Make a note of the value for Width
To render in PDF correctly Body Width + Left margin + Right margin must be less than or equal to Page width. When you see blank pages being rendered it is almost always because the body width plus margins is greater than the page width.
Remember: (Body Width + Left margin + Right margin) <= (Page width)

Below is the link where I got the solution.

http://www.sqlservercentral.com/Forums/Topic223897-150-2.aspx#bm833969

Hope it helps.

Plug-in assembly does not contain the required types or assembly content cannot be updated.


I was getting above error for my plugin. Figured out that the plugin was referring to some dlls (custom helper classes).

So putting those dll’s in the

Microsoft Dynamics CRM\CRMWeb\bin folder resolved the error.

Hope it helps.