Thursday, June 4, 2020

Appointment in Dynamic CRM using Web API


Here are the default Status and Status Reason value for an appointment entity in D365 CRM


STATUS
(statecode)
STATUS REASON
(Statuscode)
Appointment
0 : Open
1 : Free
2 : Tentative
100000000 : No Show
100000001 : Rescheduled
1 : Completed
3 : Completed
2 : Canceled
4 : Canceled
3 : Scheduled
5 : Busy
6 : Out of Office

Custom values No Show and Rescheduled are deliberately added to an Open State for one of my customer requirement.

Words of Caution: 
Making changes to existing status reasons on Appointments might break Outlook integration, as it expects certain values.

Now, let’s proceed with Common operations on an appointment by Web API and Postman


Change Status

Here we need to pass both statecode and statuscode to change the status of an appointment.

 

To Re-Open Again


Create Appointment

Here is a Json data

{
  "subject""Need to discuss about business requirement for an upcoming project",
  "location""GoldenMeeting Room 6th Floor",
  "isalldayevent"false,
  "scheduledstart""2020-02-05T19:00:00Z",
  "scheduledend""2020-02-05T19:30:00Z",
  "description""Details task break down for BRS for new project",
  "statuscode": 5,
  "ownerid@odata.bind""/systemusers(275a421e-109f-ea11-a816-000d3a591218)",
  "regardingobjectid_contact@odata.bind""/contacts(9a021bb7-4d7a-ea11-a812-000d3a3be645)"
}


  • Notice the syntax for Regarding object Id that is suppose to accept any other entity object in D365 CRM. 
  • Don't just go with schema name that is mentioned under customization section for a field.

**You need to provide an entity name with OData Bind. 

For example : To bind to Account then
"regardingobjectid_account@odata.bind""/accounts(03ac8073-1f95-ea11-a811-000d3a3be645)"

For example : To bind to Opportunity then
"regardingobjectid_opportunity@odata.bind":"/opportunities(5e17e46e-d6a4-ea11-a812-000d3a3be645)"


Create Appointment With PartyList

Here is a Json data


{
    "subject""vipin OOOOOOOOOOO - call for your furniture request",   
    "scheduledstart""2020-02-05T18:00:00Z",
    "scheduledend""2020-02-07T21:30:00Z",    
    "statuscode"5,    
    "regardingobjectid_opportunity@odata.bind":"/opportunities(5e17e46e-d6a4-ea11-a812-000d3a3be645)",    

    "appointment_activity_parties": [
        {      
            "participationtypemask"5,      
            "partyid_account@odata.bind""/accounts(3028b660-d7a4-ea11-a812-000d3a3be645)"    
        },  
        {      
            "participationtypemask"5,      
            "partyid_systemuser@odata.bind""/systemusers(37ee1ddb-cd80-ea11-a811-000d3a591aee)"    
        },
        {      
            "participationtypemask"5,      
            "partyid_contact@odata.bind""/contacts(af21be43-8559-ea11-a811-000d3a3be645)"    
        }, 
        {      
            "participationtypemask"5,      
            "partyid_lead@odata.bind""/leads(953170e4-6f8f-ea11-a811-000d3a3be645)"    
        }        
    ]
}

**Note: Queues cannot be parties on Appointment


GetAppointmentWithAccountAndOwner


{{webapiurl}}appointments(8facef82-c8a7-ea11-a812-000d3a3be645)?$select=_createdby_value,createdon,description,isalldayevent,location,_modifiedby_value,modifiedon,_ownerid_value,_regardingobjectid_value,scheduleddurationminutes,scheduledend,scheduledstart,statecode,statuscode,subject
&$expand=regardingobjectid_account_appointment($select=accountid,name,telephone1),owninguser_appointment($select=fullname,personalemailaddress,systemuserid)


GetAppointmentsByUserId

{{webapiurl}}appointments?$select=_createdby_value,createdon,description,isalldayevent,location,_modifiedby_value,modifiedon,_ownerid_value,_regardingobjectid_value,scheduleddurationminutes,scheduledend,scheduledstart,statecode,statuscode,subject
&$filter=_ownerid_value eq 2ea2971b-414c-ea11-a815-000d3a591aee


GetAppointmentById

{{webapiurl}}appointments(37c88384-4ea6-ea11-a812-000d3a3bef84)?$select=_createdby_value,createdon,description,isalldayevent,location,_modifiedby_value,modifiedon,_ownerid_value,_regardingobjectid_value,scheduleddurationminutes,scheduledend,scheduledstart,statecode,statuscode,subject


GetTodaysAppointmentsForUserId

{{webapiurl}}appointments?$select=_createdby_value,createdon,description,isalldayevent,location,_modifiedby_value,modifiedon,_ownerid_value,_regardingobjectid_value,scheduleddurationminutes,scheduledend,scheduledstart,statecode,statuscode,subject
&$filter=scheduledstart eq 2020-06-03T18:30:00Z and _ownerid_value eq 275a421e-109f-ea11-a816-000d3a591218


GetUpcomingAppointmentsForUserId

{{webapiurl}}appointments?$select=_createdby_value,createdon,description,isalldayevent,location,_modifiedby_value,modifiedon,_ownerid_value,_regardingobjectid_value,scheduleddurationminutes,scheduledend,scheduledstart,statecode,statuscode,subject 
&$filter=scheduledstart ge 2020-06-03T18:30:00Z and _ownerid_value eq 275a421e-109f-ea11-a816-000d3a591218


GetPastAppointmentsForUserId

{{webapiurl}}appointments?$select=_createdby_value,createdon,description,isalldayevent,location,_modifiedby_value,modifiedon,_ownerid_value,_regardingobjectid_value,scheduleddurationminutes,scheduledend,scheduledstart,statecode,statuscode,subject
&$filter=scheduledstart le 2020-06-03T18:30:00Z and _ownerid_value eq 275a421e-109f-ea11-a816-000d3a591218


Delete an Appointment










1 comment:

Eugene Bryant said...

Thank you for sharing such a nice post. I love it so much.Check Office Furniture Miami