Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM forum
Suggested answer

Run Report on Selected Records for Multiple Record Types

Posted on by Microsoft Employee

Hello,

I have a report that runs on selected Account records. You can check off certain Account records, and the report returns a list of Contacts associated with those Accounts (along with some other stuff, like certain Connections associated with those contacts).

This is currently working, but I would like to expand the report so you could run it by directly selecting the Contacts you want to see relationships for, rather than just by selecting their Accounts. It would also be nice to run this by selecting a Marketing List. Is there a way I could expand what I have so it can accept different types of records and alter my dataset logic based on the type of record it is being run on?

I based my report off this blog post, although I made some changes: http://www.kentom.co.uk/?p=353

I have a Main Report that is Fetchxml based. It takes the account records you have selected and passes the accountid as a parameter to a Subreport. (Unlike the blog post, my Subreport is actually SQL based, because I need to use unions and temp tables.) I won't bother to explain everything the subreport does, but for the sake of simplicity, let's just says my dataset in the subreport is:

Select * from contacts where accountid = @accountid

I'd like to make changes to my main report so it can accept different types of IDs, and will let me know which kind of record is being used. That way, my dataset in the Subreport could be something like this:

If (@recordType = 'Account')

     Select * from contacts where accountid = @recordID

Else if (@recordType = 'Contact')

     Select * from contacts where contactid = @recordID

Currently, this is what my Main Report looks like. What changes would I need to make to get something similar to the input I need to run the dataset in my Subreport?

Dataset:

<fetch distinct="false" mapping="logical" output-format="xml-platform" version="1.0">
<entity name="account" enableprefiltering="1">
<attribute name="accountid"/>
</entity>
</fetch>

Parameter:

Name: CRM_account

Default Value:

<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false"><entity name="account"><all-attributes/></entity></fetch>

Link to Subreport:

Sends as a parameter the "accountid" field from the dataset

Any help would be greatly appreciated. Thank you!

Categories:
  • Suggested answer
    naresh babu Profile Picture
    naresh babu 425 on at
    RE: Run Report on Selected Records for Multiple Record Types

    Thanks Ben for your response. It helped me

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Run Report on Selected Records for Multiple Record Types

    Hi Naresh,

    I apologize for the delay in response. I am a bit confused because it looks like you have either edited your initial response, or I was absolutely confused at the time I responded and was reading something completely different. In any case, my response above seems to not be relevant to the link you have provided.

    I am looking at your link now. From what I am reading, it seems that you are suggesting that I could create a custom button in the ribbon. This button could use javascript to determine (from the context) whether I was trying to run the report on contacts or accounts, and then pass that parameter to my report.

    This is a good idea, however, I have a limited role at this organization. I am allowed to create reports, but I don't think they want me creating any custom buttons. So unfortunately, I'm unable to try this method.

    The solution I eventually decided on was to create two almost identical reports, both with the same name. The only difference one is designed to run on contacts, the other on accounts.

    Since they have the same name, and each is configured to only appear in the proper context (either for contacts, or accounts, using the "Related Record Types" option), the user doesn't need to know that they are actually different reports.

    I usually try not to replicate code in two places like this, but it was the best solution I was able to implement. Thanks for your help.

  • naresh babu Profile Picture
    naresh babu 425 on at
    RE: Run Report on Selected Records for Multiple Record Types

    Hi Ben,

    how did you solve this error?

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Run Report on Selected Records for Multiple Record Types

    Hi Naresh,

    Thanks very much for your response. I apologize for my lack of knowledge of Fetch, I'm very new to this. I think i need a little more advice about how to use the code you provided above. Could you please explain more explicitly what I should do with that code?

    My initial thought was that you intended that I could use that code to identify the type of entity that was selected. If that's correct, I'm unsure how to use it in that way.

    Here is what I tried:

    (1)

    I tried creating a new parameter, with that code above as the default value. I thought that this would return the entity name (like "contact" or "account"). But the parameter seems to just return the text of the code, rather than the executed value as I had hoped. I'm not sure how to create a parameter that executes fetch code within it, and I could not find explanation of how to do this elsewhere. (The parameters I listed above that are like this were created automatically based on my dataset code).

    (2)

    I tried creating a dataset with an altered version of your code:

    <fetch distinct="false" mapping="logical" output-format="xml-platform" version="1.0">

    <entity name="incident" enableprefiltering="1" prefilterparametername="CRM_FilteredIncident">

    <attribute name="entityname"/>

    </entity>

    </fetch>

    It gives me an error when I try to save the dataset, saying The attribute "entityname" cannot be found for the entity "incident"

     

    (3)


    I looked up the entity "incident", and I am not understanding what it has to do with what I am trying to do here. Did you mean that just as an example, and I am supposed to change it to another entity?

  • naresh babu Profile Picture
    naresh babu 425 on at
  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Run Report on Selected Records for Multiple Record Types

    Just wanted to try to bump this question before I give up on it and just create two separate reports. I have tried several approaches which have been unsuccessful. Does anyone have any ideas/suggestions?

Helpful resources

Quick Links

Replay now available! Dynamics 365 Community Call (CRM Edition)

Catch up on the first D365 Community Call held on 7/10

Community Spotlight of the Month

Kudos to Saurav Dhyani!

Congratulations to the June Top 10 community leaders!

These stars go above and beyond . . .

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 287,696 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 225,490 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans