Reopen Closed Appointment Using JavaScript in D365 CRM

 Introduction:

 

When an appointment is closed in D365 CRM, the appointment is not editable. There can be a requirment when Users wish to edit the closed appointment and add some missing data. This can be achieved by adding a new button on the Appointment form.

 

Solution:

 

Add a new button and use below JavaScript.

var AppointmentForm = 

{

       setActive:function(primaryControl)

 {

        var formContext= primaryControl;

        var status= formContext.getAttribute("statecode").getValue();

        if (status==1)

        {

            formContext.getAttribute("statecode").setValue(0);

            formContext.getAttribute("statuscode").setValue(1); 

            formContext.data.save();

        }

    }

}

 To understand the status and status reason details, you can refer the Microsoft document- https://docs.microsoft.com/en-us/dynamics365/customer-engagement/web-api/appointment?view=dynamics-ce-odata-9

 

Note that, you need to update both statecode and statuscode, trying to update only one will give a system error.


Comments

Popular posts from this blog

The supplied reference link is invalid Error in Cloudflows

Retrieve Email Recipients (TO, CC, BCC) in Cloud Flow

Set Dynamic Recipients of D365 Email in Power Automate