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 :
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,216 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

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 > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
Martin Dráb Profile Picture

Martin Dráb 51 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 38 Super User 2025 Season 2

#3
#ManoVerse Profile Picture

#ManoVerse 31

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans