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,204 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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Verified Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,503 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans