web
You’re offline. This is a read only version of the page.
close
Skip to main content
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)
  • Jacooooob Profile Picture
    75 on at
    RE: Get Interaction/Appointment Count against record

    Thanks that worked!!

  • Verified answer
    LeoAlt Profile Picture
    16,331 Moderator on at
    RE: Get Interaction/Appointment Count against record

    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

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…

Mansi Soni – Community Spotlight

We are honored to recognize Mansi Soni as our August 2025 Community…

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Service | Customer Service, Contact Center, Field Service, Guides

#1
Abhilash Warrier Profile Picture

Abhilash Warrier 100 Super User 2025 Season 2

#2
Suresh Kulla Profile Picture

Suresh Kulla 72 Super User 2025 Season 2

#3
DAnny3211 Profile Picture

DAnny3211 54

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans