Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Unanswered

Javascript not working on LeadSourceCode field

(0) ShareShare
ReportReport
Posted on by 18

JAVASCRIPT TO HIDE CERTAIN LEAD SOURCE OPTIONS

I'm trying to hide certain option values from the LeadSource choice fields that we don't want selectable from the dropdown no longer. I'm using the code below to try to remove one of the options, however, the code doesn't seem to work on the leadsourcecode field.

oContactCustomization2 = {

hideLeadSource: function (context) {
var formContext = context.getFormContext();
var testOptionSet = formContext.getControl("leadsourcecode");
if (testOptionSet !== null) {
testOptionSet.removeOption(12);
}
}

};

I've tried the exact same code on a different custom field and it worked successfully, so I'm not sure if there's something specific to the out-of-box Lead Source field that makes it so the Javascript doesn't work. If anyone has any insight or ideas as to how I can use JS on the standard Lead Source field, that would be helpful. My last resort is to duplicate the lead source field, but that would also require copying over all the data from the standard field to the custom one. 

Thank you!

  • snoek Profile Picture
    18 on at
    RE: Javascript not working on LeadSourceCode field

    Yes, I've also tried values other than 12, but for whatever reason it still will not work on the standard Lead Source field.

  • Guido Preite Profile Picture
    54,077 Moderator on at
    RE: Javascript not working on LeadSourceCode field

    double check if the value of the option you want to remove is correct

  • necsa Profile Picture
    3,455 on at
    RE: Javascript not working on LeadSourceCode field

    Hi,

    I try exactly the same code on my environment and it works. Please, did you use correct OptionSet element value? 12 is the OptionSet Value of what do you want to hide?

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

Jainam Kothari – Community Spotlight

We are honored to recognize Jainam Kothari as our June 2025 Community…

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

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

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Daivat Vartak (v-9davar) Profile Picture

Daivat Vartak (v-9d... 671 Super User 2025 Season 1

#2
Vahid Ghafarpour Profile Picture

Vahid Ghafarpour 167 Super User 2025 Season 1

#3
Muhammad Shahzad Shafique Profile Picture

Muhammad Shahzad Sh... 138 Most Valuable Professional

Product updates

Dynamics 365 release plans