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 :
Service | Customer Service, Contact Center, Fie...
Answered

Get Interaction/Appointment Count against record

(0) ShareShare
ReportReport
Posted on by 75


Hello,

I have a request to show an error message when a ribbon button is clicked.

This error message should only appear when there is less than 4 appointments/interactions against this record.

I am unsure on how to get this record count so I can conditionally show this error message.

Any ideas?

Thanks!

I have the same question (0)
  • Verified answer
    LeoAlt Profile Picture
    16,331 Moderator on at

    Hi partner,

    It is possible to query the related appointments according to the current record form.

    We just need to get the current record id and use web api to query the related activities according to regording field.

    Here are the sample code for you.


    function getAppointmentCounts(executionContext){
        //get current record id
        var id = Xrm.Page.data.entity.getId();
        id=id.substring(1,id.length-1);
        var count=0;
        //get the related appointments' count.
        Xrm.WebApi.retrieveMultipleRecords("appointment""?$filter=_regardingobjectid_value eq '"+id+"'").then(
            function success(result) {
            count=result.entities.length;
            alert(count);

        })
    }

    Pay attention that the "Regarding" field should be used as "_regardingobjectid_value" when filter it in web api.

    1541.pastedimage1570155222200v1.png

    Hope it helps.

    Best Regards,

    Leo

  • Jacooooob Profile Picture
    75 on at

    Thanks that worked!!

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 > Service | Customer Service, Contact Center, Field Service, Guides

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 61 Super User 2025 Season 2

#2
Siv Sagar Profile Picture

Siv Sagar 52 Super User 2025 Season 2

#3
Daniyal Khaleel Profile Picture

Daniyal Khaleel 42 Most Valuable Professional

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans