web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

CRM view of Opportunity records with Notes attachment

(0) ShareShare
ReportReport
Posted on by 943

Hi All,

I need to create a system view in CRM 2013 for Opportunity records, however the condition for the view is that it should only contain those Opportunity records which do not have Notes attachment. 

Earlier I was thinking it's very easy to create this view but till now I am not able to create right filter. Please help me to create this view. 

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    ManirajKV Profile Picture
    1,477 on at

    Hi,

    through Notes -> IsDocument attribute we could filter it.

    8244.Capture.JPG

  • Suggested answer
    BackToTheCrm Profile Picture
    on at

    Hello Varun,

    Indeed, it's very easy to create. Reproduce this Advanced find query :

    3000.Advanced-Find.png

    As you can see you only need to add an association on Notes with no filter in it.

  • Aileen Gusni Profile Picture
    44,524 on at

    Hi Varun

    If your query purpose is to get the list of opportunities with Notes but the note is not containing attachment or document then you can use the adv find by using Opportunity then go to the related entity find Notes and use the isdocument attribute to No

    But if your purpose to query Opportunity without any notes attached then is not possible using crm out of the box query to do query with "not in " clause.

    Hope this helps

    Thanks

  • Varun Singh Profile Picture
    943 on at

    Hi Maniraj,

    I have tried this condition earlier also. There is some bug in CRM. If I put above filter on Notes related entity then the result of view is fetching those results which have attachment also.

  • Varun Singh Profile Picture
    943 on at

    Hi Aileen,

    I have tried this earlier many times but when I am putting isdocument equal to NO, the result will contain attached document records also. I think it's bug in CRM (We have migrated our CRM from 2011 to CRM 2015)

  • Suggested answer
    Dhaval mistry Profile Picture
    810 on at

    Hi

    What I understand your question is: you need to list out oppotunity which doesn't have Note.

    using advance find of CRM Out of box, you can't implement left join on fatch XML

    But you can do it using fatchXML using C# code (custom web resource) or SSRS report.

    Left outer join 

    https://msdn.microsoft.com/en-us/library/dn531006.aspx?f=255&MSPPError=-2147217396

    Wish it helps!

  • Suggested answer
    ManirajKV Profile Picture
    1,477 on at

    Yes, It will not work for one scenario. (Its not a bug in CRM).

    Scenario: "Opportunity X" record has more than one notes (one note with attachment and one note without attachment)

    Notes entity will associate two records with "Opportunity X". So only above fetch is not working on this scenario.

    You can achieve your requirement using below fetch:

    <fetch distinct="true" mapping="logical" output-format="xml-platform" version="1.0" >
        <entity name="opportunity">
            <attribute name="name" />
            <link-entity name="annotation" from="objectid" to="opportunityid" alias="an" link-type="outer" >
                <attribute name="objectid" />
                <filter type="and" >
                    <condition attribute="isdocument" value="1" operator="eq" />
                </filter>
            </link-entity>
            <filter type="and" >
                <condition entityname="an" attribute="objectid" operator="null" />
            </filter>
        </entity>
    </fetch>
    

    Through savequeryentity, you can create view in CRM. Its a one time activity.
    Please follow the below to do the same.

    8664.Untitled.png

  • Varun Singh Profile Picture
    943 on at

    Hi Maniraj,

    Thanks for your help. Would you please help, how to make this view (For example from Plugin or somewhere else. Please little bit elaborate.

  • Verified answer
    ManirajKV Profile Picture
    1,477 on at

    Hi,
    1. Create one console application
    2. replace the below code in Program.cs file
    3. Add reference of Microsoft.Xrm.Sdk.dll, Microsoft.Xrm.Client.dll

    ***************************************************
    using Microsoft.Xrm.Client;
    using Microsoft.Xrm.Client.Services;
    using Microsoft.Xrm.Sdk;
    using System;
    namespace CRMCustomDemo
    {
    class Program
    {
    static void Main(string[] args)
    {
    try
    {
    // for crm online instance
    CrmConnection connection = CrmConnection.Parse("URL=https://****.crm5.dynamics.com/; username=***@***.com; password=****");
    OrganizationService _service = new OrganizationService(connection);
    var fetchXML = "<fetch distinct=\"true\" mapping=\"logical\" output-format=\"xml-platform\" version=\"1.0\" >";
    fetchXML += "<entity name=\"opportunity\">";
    fetchXML += "        <attribute name=\"name\" />";
    fetchXML += "        <link-entity name=\"annotation\" from=\"objectid\" to=\"opportunityid\" alias=\"an\" link-type=\"outer\" >";
    fetchXML += "            <attribute name=\"objectid\" />";
    fetchXML += "            <filter type=\"and\" >";
    fetchXML += "                <condition attribute=\"isdocument\" value=\"1\" operator=\"eq\" />";
    fetchXML += "            </filter>";
    fetchXML += "        </link-entity>";
    fetchXML += "        <filter type=\"and\" >";
    fetchXML += "            <condition entityname=\"an\" attribute=\"objectid\" operator=\"null\" />";
    fetchXML += "        </filter>";
    fetchXML += "    </entity>";
    fetchXML += "</fetch>";
    Entity entity = new Entity("savedquery");
    entity["name"] = "NoAttachmentsView";
    entity["fetchxml"] = fetchXML;
    entity["returnedtypecode"] = "opportunity";
    entity["querytype"] = 0;
    _service.Create(entity);
    }
    catch(Exception ex)
    {
    Console.WriteLine(ex.Message);
    }
    }
    }
    }
    If you couldn't get it done, please drop a mail to me @ manirajcareer@live.com will share you the solution file.
  • Varun Singh Profile Picture
    943 on at

    Hi Maniraj,

    Once again thank you. I am able to create View from console application. However the result is same. It's giving Opportunity records which have attachment also. I need only those Opportunity records which do not have any attachment at all.

    Below is the fetchXML variable which I am using.


    var fetchXML = "<fetch distinct=\"true\" mapping=\"logical\" output-format=\"xml-platform\" version=\"1.0\" >";
    fetchXML += "<entity name=\"opportunity\">";
    fetchXML += " <attribute name=\"name\" />";
    fetchXML += " <filter type=\"and\" >";
    fetchXML += " <filter type=\"or\" >";
    fetchXML += " <condition attribute=\"new_state\" operator=\"eq\" value=\"100000006\" /> ";
    fetchXML += " <condition attribute=\"new_state\" operator=\"eq\" value=\"100000003\" /> ";
    fetchXML += " </filter>";
    fetchXML += " <condition attribute=\"new_closeddate\" operator=\"this-year\" />";
    fetchXML += " </filter>";
    fetchXML += " <link-entity name=\"annotation\" from=\"objectid\" to=\"opportunityid\" alias=\"an\" link-type=\"outer\" >";
    fetchXML += " <attribute name=\"objectid\" />";
    fetchXML += " <filter type=\"and\" >";
    fetchXML += " <condition attribute=\"isdocument\" value=\"0\" operator=\"eq\" />";
    fetchXML += " </filter>";
    fetchXML += " </link-entity>";
    fetchXML += " <filter type=\"and\" >";
    fetchXML += " <condition entityname=\"an\" attribute=\"objectid\" operator=\"null\" />";
    fetchXML += " </filter>";
    fetchXML += " </entity>";
    fetchXML += "</fetch>";

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
JS-09031509-0 Profile Picture

JS-09031509-0 3

#2
AS-17030037-0 Profile Picture

AS-17030037-0 2

#2
Mark Eckert Profile Picture

Mark Eckert 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans