Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Campaign Lead Id - JavaScript - Dynamics 365

Posted on by 3,702

Guys need to get the related lead id from the campaign entity in java script

*This post is locked for comments

  • Kishor Kumar Profile Picture
    Kishor Kumar 3,702 on at
    RE: Campaign Lead Id - JavaScript - Dynamics 365

    When I added the code as above function getting an error like One of the scripts for this record has caused an error. For more details, download the log file.

    ReferenceError: **** is not defined at eval

  • ChangeFrenzoId Profile Picture
    ChangeFrenzoId 465 on at
    RE: Campaign Lead Id - JavaScript - Dynamics 365

    Then use the below code:

    var req = new XMLHttpRequest();
    req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.2/leads?$select=_campaignid_value,_customerid_value,leadid&$filter=_campaignid_value eq 00000000-CAMPAIGN-GUID-00000000", false);
    req.setRequestHeader("OData-MaxVersion", "4.0");
    req.setRequestHeader("OData-Version", "4.0");
    req.setRequestHeader("Accept", "application/json");
    req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
    req.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");
    req.onreadystatechange = function() {
        if (this.readyState === 4) {
            req.onreadystatechange = null;
            if (this.status === 200) {
                var results = JSON.parse(this.response);
                for (var i = 0; i < results.value.length; i++) {
    
                    var leadid = results.value[i]["leadid"]; //YOUR REQUIRED LEADID
    
                }
            } else {
                Xrm.Utility.alertDialog(this.statusText);
            }
        }
    };
    req.send();
  • Kishor Kumar Profile Picture
    Kishor Kumar 3,702 on at
    RE: Campaign Lead Id - JavaScript - Dynamics 365

    Hi Piyush, thanks for the reply but we don't have leadid lookup field in the campaign form and we have grid loading with leads that are related to Campaign

  • ChangeFrenzoId Profile Picture
    ChangeFrenzoId 465 on at
    RE: Campaign Lead Id - JavaScript - Dynamics 365

    Hi Kishor,

    Assuming, you have leadid lookup field in campaign entity form, then use below code to get the lead id:

    Xrm.Page.getAttribute("leadid").getValue()[0].id;

    Hope it help you!

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 Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans