Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics 365 | Integration, Dataverse...
Suggested answer

Code to reopen the closed leads using web api

(1) ShareShare
ReportReport
Posted on by 2

Hi,

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

pastedimage1616074822362v1.png

  • Suggested answer
    Ali Raza Profile Picture
    Ali Raza 10 on at
    Code to reopen the closed leads using web api
    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.");
        }
    }
  • Suggested answer
    meelamri Profile Picture
    meelamri 13,206 User Group Leader on at
    RE: Code to reopen the closed leads using web api

    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
        }
    );

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

Congratulations 2024 Spotlight Honorees

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December

Congratulations to our December super stars! 🥳

Start Your Super User Journey

Join the ranks of our community heros! 🦹

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,735 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,466 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans