Quantcast
Channel: BugsOli's xRM blog » Microsoft CRM
Viewing all articles
Browse latest Browse all 52

How-to series: Create a custom report (part 3)

$
0
0

Okay now, I’ve already dealt with the basics of custom report creation (see Part 1 & Part 2 on this blog) so now I’m going to show you how to create a report from scratch for displaying the service activities in an other way.

In this how-to, I’ll still be using Microsoft SQL Server Report Builder 2.0, and I’ll start from a blank report to show how easy it is to create a new custom report.

Microsoft CRM displays the service activities in a “GANTT” style view, with the resources being on the Y-axis and the time being on the X-axis, like this:image

The business requirement for this report is to display the service activities view in a reversed way, meaning that the resource would be on the X-axis and the time would be on the Y-axis, like this:

image

In terms of CRM display, this is what you get from the service activities calendar:Capture111

And this is the result we would like to achieve:

image

Hopefully, this is just a table with rows and columns, so as long as we can retrieve the correct data, it should not be too difficult to create this kind of report output.

Therefore, the scheduling entity Visio diagram provided by Microsoft comes in handy (download the Microsoft Dynamics CRM 4.0 Logical Database Diagrams: http://www.microsoft.com/downloads/details.aspx?FamilyId=B73912E8-861E-43AE-97B4-72B3E809F287&displaylang=en) as it shows that the service activities are stored as service appointments:

image

The other thing that is interesting is the fact that the service appointment is basically an appointment, which derives from the activity, resulting in a sharing of attributes such as the ‘activityid’.

This field is duplicated a number of times in various tables where we can find useful information such as: who are the resources involved in the service appointment, where is located, at what time, etc.

In my case, I only want:

  • the name of the involved resources (only the users, no equipments whatsoever)
  • the event’s duration
  • the appointment’s start & end dates (the start date will help me know which week the event should take place)
  • the subject (or title) of the event
  • to know if the event is internal or external (with the help of a new attribute DEV_ISEXTERNAL)

The SQL query I will use to return this set of data is here:

set datefirst 1;

select    
        CRMAF_FilteredServiceAppointment.subject,
        CRMAF_FilteredServiceAppointment.serviceidname,
        CRMAF_FilteredServiceAppointment.scheduledstart,
        CRMAF_FilteredServiceAppointment.scheduledend,
        CRMAF_FilteredServiceAppointment.scheduleddurationminutes,
        datepart(ISO_WEEK, CRMAF_FilteredServiceAppointment.scheduledstart) as startweek,
        datepart(WEEKDAY, CRMAF_FilteredServiceAppointment.scheduledstart) as startday,
        datename(dw,datepart(WEEKDAY, CRMAF_FilteredServiceAppointment.scheduledstart) - 1) as dayofwk,
        (case when DATEPART(HH,CRMAF_FilteredServiceAppointment.scheduledstart) < 12 then 'AM' else 'PM' end) as ampm,
        isnull(CRMAF_FilteredServiceAppointment.dev_isexternal, 0) as dev_isexternal,
        SUBSTRING(CRMAF_FilteredActivityParty.partyidname, 0, CHARINDEX(' ',CRMAF_FilteredActivityParty.partyidname) + 2) + '.' AS partyidname
from FilteredServiceAppointment as CRMAF_FilteredServiceAppointment
inner join FilteredActivityParty as CRMAF_FilteredActivityParty on CRMAF_FilteredServiceAppointment.activityid = CRMAF_FilteredActivityParty.activityid
where    
        CRMAF_FilteredServiceAppointment.statecode <> 2
        --and ( CRMAF_FilteredServiceAppointment.scheduledstartutc >= dbo.fn_BeginOfLastWeek(GetUTCDate()) 
        --and CRMAF_FilteredServiceAppointment.scheduledstartutc <= dbo.fn_EndOfLastWeek(GetUTCDate()) )
        and CRMAF_FilteredActivityParty.participationtypemask = 10 -- Resources only
group by 
        CRMAF_FilteredServiceAppointment.subject,
        CRMAF_FilteredServiceAppointment.serviceidname,
        CRMAF_FilteredServiceAppointment.scheduledstart,
        CRMAF_FilteredServiceAppointment.scheduledend,
        CRMAF_FilteredServiceAppointment.scheduleddurationminutes,
        datepart(ISO_WEEK, CRMAF_FilteredServiceAppointment.scheduledstart),
        datepart(WEEKDAY, CRMAF_FilteredServiceAppointment.scheduledstart),
        datename(dw,datepart(WEEKDAY, CRMAF_FilteredServiceAppointment.scheduledstart) - 1),
        (case when DATEPART(HH,CRMAF_FilteredServiceAppointment.scheduledstart) < 12 then 'AM' else 'PM' end),
        isnull(CRMAF_FilteredServiceAppointment.dev_isexternal, 0),
        SUBSTRING(CRMAF_FilteredActivityParty.partyidname, 0, CHARINDEX(' ',CRMAF_FilteredActivityParty.partyidname) + 2) + '.' 
order by
        CRMAF_FilteredServiceAppointment.scheduledstart,
        CRMAF_FilteredServiceAppointment.scheduledend

The result will look like this:

image

Now that we have our result, let’s build the report!

  1. Launch the Report Builder
  2. Create a new data source, name it ‘CRM’ and configure it as follows:

    image

    image

  3. Create a new dataset, name it ‘DSScheduledActivities’ and configure it as follows:
    • Choose the ‘CRM’ data source
    • Choose the ‘Text’ query type and paste the SQL query located above
    • Click on OK to generate the fields that you’ll use afterwards in the report

    image

  4. Once your dataset is created, you can add a new table or matrix to your report; in this case, I’ll use the ‘Table Wizard’ provided by the Report Builder to create my table
    • Choose the newly created dataset ‘DSScheduledActivities’:

      image

    • Position the row (Y-axis) and column (X-axis) groups according to the business requirements (since our grouping is made in SQL, you can choose the ‘First’ function for the subject):

      image

    • Choose the layout & style you want to apply to your report:

      image image

    • After the last step, your report is ready to test! I’ve spent some time fiddling around with the report and here is the result…not bad isn’t it?

image

NB: For easy integration and consistency, I’ve copied the header and footer from a previous CRM report so I will not talk about it here.

The next step in this series is to add some graphics and maybe to add the vacation and business closure dates.

Hope this post will help someone :-)


Viewing all articles
Browse latest Browse all 52

Latest Images

Trending Articles





Latest Images