Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

Dynamic query based on selected records

Posted on by 450

Hi there All.
I want to create a report that produce results based on the records that end-user have selected.
This report is on my custom entity that has relation with sales order, sales order as primary entity and my custom entity as related entity.
Previously I have created records based on the parameters, but the end-user entered the parameters in the report.
Anyways, For this , want to pass selected sales order Id as parameter to the report, Should I use Filtered view of every entity?
I have created a parameter named @CRM_SalesOrderId. 

with this query :

SELECT        SalesOrderId
FROM            FilteredSalesOrder AS CRMAF_FilteredSalesOrderId;

I have set the Sales Order Id as default value and available value of the parameter.

And this is my main Query :

SELECT     Filteredbmsd_receipt.bmsd_totalamount_base, FilteredSalesOrder.salesorderid, FilteredSalesOrder.new_order_code, FilteredSalesOrder.name AS salesordername, 
                      methodreceiptstring.AttributeValue AS methodreceiptattributevalue, methodreceiptstring.AttributeValue AS methodreceiptattributevalue, 
                      methodreceiptstring.AttributeName AS methodreceiptattributename, methodreceiptstring.Value AS methodreceiptvalue, 
                      receiptstatusstring.AttributeValue AS receiptstatusstringvalue, receiptstatusstring.AttributeValue AS receiptstatusstringattributevalue, 
                      receiptstatusstring.AttributeName AS receiptstatusstringname, receiptstatusstring.Value
FROM         Filteredbmsd_receipt INNER JOIN
                      FilteredStringMap AS methodreceiptstring ON methodreceiptstring.AttributeValue = Filteredbmsd_receipt.bmsd_receiptmethod AND 
                      methodreceiptstring.AttributeValue = 2 AND methodreceiptstring.AttributeName = 'bmsd_ReceiptMethod' AND methodreceiptstring.LangId = 1088 INNER JOIN
                      FilteredStringMap AS receiptstatusstring ON receiptstatusstring.AttributeValue = Filteredbmsd_receipt.bmsd_receiptstatus AND 
                      receiptstatusstring.AttributeName = 'bmsd_receiptstatus' AND receiptstatusstring.LangId = 1088 
                      INNER JOIN FilteredSalesOrder ON ( FilteredSalesOrder.salesorderid=Filteredbmsd_receipt.bmsd_orderid)
                      where Filteredbmsd_receipt.bmsd_orderid in (@CRM_SalesOrderId)
ORDER BY FilteredSalesOrder.new_order_code, methodreceiptvalue


I have created This as my Main Query, and that one as my parameter query.
Did I do right?
Now when enter the main query in the main data set and click Referesh Fields It gives me  :
An item with the same key has already been added.



I removed my created Parameter (@CRM_SalesOrderId) to allow the query to created the parameter, But no success. 
How can I solve this?And after created that I must select
Forms for related record types;Lists for related record types;Reports area

in display field of the report, right?

*This post is locked for comments

  • Verified answer
    Mahadeo Matre Profile Picture
    Mahadeo Matre 17,021 on at
    RE: Dynamic query based on selected records

    Hi Albert,

    In your query you have " methodreceiptstring.AttributeValue AS methodreceiptattributevalue" two times, that's why you are getting this error "An item with same key has already been added.

    Either you need to remove one or need to change name of attribute as  "methodreceiptstring.AttributeValue AS methodreceiptattributevalue1"

    hope this will help..

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,240 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,149 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans