web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

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!

I have the same question (0)
  • necsa Profile Picture
    3,455 on at

    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?

  • Guido Preite Profile Picture
    54,086 Moderator on at

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

  • snoek Profile Picture
    18 on at

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

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 108 Super User 2025 Season 2

#2
Jimmy Passeti Profile Picture

Jimmy Passeti 50 Most Valuable Professional

#3
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 49 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans