Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Dynamic query based on selected records

(0) ShareShare
ReportReport
Posted on by 452

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
    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

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Microsoft Dynamics CRM (Archived)

#1
Mohamed Amine Mahmoudi Profile Picture

Mohamed Amine Mahmoudi 83 Super User 2025 Season 1

#2
Community Member Profile Picture

Community Member 52

#3
Victor Onyebuchi Profile Picture

Victor Onyebuchi 6

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans