web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Suggested Answer

Code to reopen the closed leads using web api

(1) ShareShare
ReportReport
Posted on by 10

Hi,

I need code to reopen or reactivate the closed leads using web api,similar to Reactivate lead button.

pastedimage1616074822362v1.png

I have the same question (0)
  • Suggested answer
    meelamri Profile Picture
    13,218 User Group Leader on at

    Hi, 

    //set statecode to 0 aka open
    var data ={"statecode": 0}
    var leadId = "8F4FA496-3FF2-E311-9864-A45D36FC5F1C"; 
    
    // update the record
    Xrm.WebApi.updateRecord("lead", leadId, data).then(
        function success(result) {
            console.log("Lead updated");
            // perform operations on record update
        },
        function (error) {
            console.log(error.message);
            // handle error conditions
        }
    );

  • Suggested answer
    Ali Raza Profile Picture
    10 on at
    Please copy the same JavaScript code into your web resource without any changes.
     
    function reactivateLead() {
    debugger;
        var leadId = Xrm.Page.data.entity.getId(); // Current lead ka ID lete hain
        if (leadId) {
            var entityFormOptions = {};
            entityFormOptions["entityName"] = "lead";
            entityFormOptions["entityId"] = leadId;
            var parameters = {};
            parameters["statuscode"] = 1; // Status code for reactivation
            parameters["statecode"] = 0;   // State code for active
            Xrm.WebApi.updateRecord("lead", leadId, parameters).then(
                function success(result) {
                    console.log("Lead reactivated successfully.");
                    // Optionally, you can refresh the form or redirect
                    Xrm.Page.data.refresh();
                },
                function (error) {
                    console.error("Error reactivating lead: " + error.message);
                    alert("Error: " + error.message);
                }
            );
        } else {
            alert("Lead ID not found.");
        }
    }

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
Pallavi Phade Profile Picture

Pallavi Phade 102 Super User 2026 Season 1

#2
11manish Profile Picture

11manish 67

#3
Abhilash Warrier Profile Picture

Abhilash Warrier 55 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans