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)

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

I have the same question (0)
  • Suggested answer
    Alex Fun Wei Jie Profile Picture
    33,628 on at

    Hi,

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

    docs.microsoft.com/.../retrievemultiplerecords

  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at

    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 .

  • Verified answer
    gdas Profile Picture
    50,091 Moderator on at

    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();
    }
  • martingr Profile Picture
    600 on at

    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?

  • Suggested answer
    gdas Profile Picture
    50,091 Moderator on at

    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

  • Suggested answer
    Rawish Kumar Profile Picture
    13,758 on at

    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"];

  • martingr Profile Picture
    600 on at

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

  • Verified answer
    gdas Profile Picture
    50,091 Moderator on at

    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

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