Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

count number of notes with javascript

(0) ShareShare
ReportReport
Posted on by 600

Hi!

As mentioned in this thread there is possible to count the number of records in a subgrid (https://community.dynamics.com/crm/b/passiondynamics/archive/2018/06/24/count-total-subgrid-records-in-dynamics-crm-using-javascript

But is there a way to count number of notes in social pane? Or display notes in a subgrid? I cannot see that any of this is possible. The issue is that it is difficult for the users to se if there are notes in the section without clicking 

Thanks for answers

*This post is locked for comments

  • Verified answer
    gdas Profile Picture
    gdas 50,089 Moderator on at
    RE: count number of notes with javascript

    This the entity id , which I found from the record URL , once the record is open you need to click on pop-out button in the form top corner button , you can have a look my video or below article -

    arunpotti.wordpress.com/.../how-to-get-guid-of-the-record-in-crm-online

  • martingr Profile Picture
    martingr 600 on at
    RE: count number of notes with javascript

    Thanks again! Just one more question: where did you get the value in step 4?

  • Suggested answer
    Rawish Kumar Profile Picture
    Rawish Kumar 13,756 on at
    RE: count number of notes with javascript

    In addition to Goutam's response. if you select the Retrieve count to "yes" on rest builder screen you will be able to get the count as  var recordCount = results["@odata.count"];

  • Suggested answer
    gdas Profile Picture
    gdas 50,089 Moderator on at
    RE: count number of notes with javascript

    Hi Martin,

    Please have a look -

    2019_2D00_02_2D00_12_5F00_15_2D00_46_2D00_12.png

    2019_2D00_02_2D00_12_5F00_15_2D00_46_2D00_12.png

  • martingr Profile Picture
    martingr 600 on at
    RE: count number of notes with javascript

    Thanks Goutam! This seems to work :-) I saw your youtube video. could you share screenshot of rest API builder so I cant see how you did this?

  • Verified answer
    gdas Profile Picture
    gdas 50,089 Moderator on at
    RE: count number of notes with javascript

    Hi Martin ,

    Please find below code which will give you count of notes -

    function FormOnloadNoteCount()
    {
        var objectID =Xrm.Page.data.entity.getId();
        objectID =objectID.replace("{","").replace("}","");
        var req = new XMLHttpRequest();
        req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v9.1/annotations?$select=annotationid,notetext,subject&$filter=_objectid_value eq "+ objectID +"", true);
        req.setRequestHeader("OData-MaxVersion", "4.0");
        req.setRequestHeader("OData-Version", "4.0");
        req.setRequestHeader("Accept", "application/json");
        req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
        req.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");
        req.onreadystatechange = function() {
            if (this.readyState === 4) {
                req.onreadystatechange = null;
                if (this.status === 200) {
                    var results = JSON.parse(this.response);
                    var numberOfNotes =  results.value.length ;
                    Xrm.Page.getAttribute("new_numberOfNotes").setValue(numberOfNotes); // Create a whole number field and set the count
    
                    //for (var i = 0; i < results.value.length; i++) {
                    //    var annotationid = results.value[i]["annotationid"];
                    //    var notetext = results.value[i]["notetext"];
                    //    var subject = results.value[i]["subject"];
                    //}
                } else {
                    Xrm.Utility.alertDialog(this.statusText);
                }
            }
        };
        req.send();
    }
  • Suggested answer
    gdas Profile Picture
    gdas 50,089 Moderator on at
    RE: count number of notes with javascript

    Hi Martin,

    You can call rest API to get number of notes in the javascript  or create roll-up field to get the total number of notes for a record . See here how to create rest API ,in the result you need to retrieve the length for retrievemultiple.

    www.youtube.com/watch

    There is a limitation that you can not show subgrid of note in your form , workaround would be create custom entity and configure a workflow push the notes at the time of note creation.

    Include custom entity subgrid in the forms .

  • Suggested answer
    Alex Fun Wei Jie Profile Picture
    Alex Fun Wei Jie 33,626 on at
    RE: count number of notes with javascript

    Hi,

    you can use webapi to retrieve the notes and get the total records from there.

    docs.microsoft.com/.../retrievemultiplerecords

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,436 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans