Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

get Contacts of Lead and Accounts in Option Set

(0) ShareShare
ReportReport
Posted on by 56

Hi

I am trying to populate Lead Contacts into an OptionSet from JavaScript. I am getting errors. I have to populate either Lead or Account, Contacts in an Option Set. 

Lookup to get lead customers

function addLeadCustomFilterLookUp()
{
    debugger;
    try {

        var param_LeadId = Xrm.Page.getAttribute("lead_optionSetValue"); // *** Get Lead Value from Option Set is Returning NULL Value 
       

if (param_LeadId != null && param_LeadId != undefined) {
            //alert('Lead ID Value: ' + param_LeadId);
            //alert('Dekh Yaaar: ' + GetOptionSetValue("field_lead"));
            //var Acct = Xrm.Page.getAttribute("field_casetypec");
            //alert("Checking Value : " + Acct);
            var filter = "<filter type='and'>" +
                "<condition attribute='field_lead' operator='eq' value='" + param_LeadId + "'/>" +
              "</filter>";

            //filter booth services based on the booth selected in participant screen
            Xrm.Page.getControl("primarycontactid").addCustomFilter(filter);

        }
    }
    catch (e) {
        throw new Error(e.message);
    }

*This post is locked for comments

  • uhh Profile Picture
    56 on at
    RE: get Contacts of Lead and Accounts in Option Set

    thank you very much for support. 

  • Verified answer
    ajyendra Profile Picture
    1,738 on at
    RE: get Contacts of Lead and Accounts in Option Set

    Hi,

    if you want to get value/text of optionset try this:

    var obj = Xrm.Page.getAttribute("fieldSchemaName");
        if (obj != null) {
            //Get OptionSet Text
            var optionSetText = obj.getText();
            //Get OptionSet Val
    var optionSetValue = obj.getValue();

    @TallyLoDuky is right if you want tofilter your lookup then you should add this code:

    Xrm.Page.getControl("primarycontactid").addPreSearch(function () {

                          Xrm.Page..getControl("primarycontactid").addCustomFilter(fetchFilter);

    Here is Full Code try This:

    function addLeadCustomFilterLookUp()
    {
        debugger;
        try {

            var param_LeadId = Xrm.Page.getAttribute("lead_optionSetValue"); // *** Get Lead Value from Option Set is Returning NULL Value 
           

    if (param_LeadId != null && param_LeadId != undefined) {
                

            //Get OptionSet Text
            var optionSetText = param_LeadId.getText();
            //Get OptionSet Val
    var optionSetValue = param_LeadId.getValue();

                As per your need you can select optionSetText/optionSetValue for filter
                var filter = "<filter type='and'>" +
                    "<condition attribute='field_lead' operator='eq' value='" + optionSetValue  + "'/>" +
                  "</filter>";

                //filter booth services based on the booth selected in participant screen
               

    Xrm.Page.getControl("primarycontactid").addPreSearch(function () {

                          Xrm.Page..getControl("primarycontactid").addCustomFilter(filter);



            }
        }
        catch (e) {
            throw new Error(e.message);
        }

                       });

    Thanks

    Ajyendra

    If this answer is helpful.Please Mark as Verified.

  • Verified answer
    Community Member Profile Picture
    on at
    RE: get Contacts of Lead and Accounts in Option Set

    you're missing part of it.  it's to be a call back from the addPreSearch method

                       formContext.getControl("primarycontactid").addPreSearch(function () {

                           formContext.getControl("primarycontactid").addCustomFilter(fetchFilter);

                       });

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

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Leaderboard > Microsoft Dynamics CRM (Archived)

#1
Mohamed Amine Mahmoudi Profile Picture

Mohamed Amine Mahmoudi 83 Super User 2025 Season 1

#2
Community Member Profile Picture

Community Member 54

#3
Victor Onyebuchi Profile Picture

Victor Onyebuchi 6

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans