web
You’re offline. This is a read only version of the page.
close
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 458

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

I have the same question (0)
  • Verified answer
    Mahadeo Matre Profile Picture
    17,021 on at

    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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans