Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Show different values in for a single option set field

(0) ShareShare
ReportReport
Posted on by

Hi everyone, 

I have 2 main account forms: FormA & FormB

and I have a field called "accountType" (option set) in both forms with values: A1, A2, A3, A4, A5

I would like to see the values A1, A2, and A3 in FormA in accountType optionset and I would like to see the values A4 and A5 in FormB in accountType optionset.

I'm guessing I would have to use some JavaScripting. Does anyone have the code for this requirement?

Thank you!

*This post is locked for comments

  • Verified answer
    Community Member Profile Picture
    on at
    RE: Show different values in for a single option set field

    I've got it to work now,

    It was an issue with the else if as well as the quotation marks. Here is my code:

    function agentTypeOptionSetLoad() {

       var formName = Xrm.Page.ui.formSelector.getCurrentItem().getLabel();

       if (formName == "Account - Organization") {

           Xrm.Page.getControl('new_accounttype').removeOption(3);

           Xrm.Page.getControl('new_accounttype').removeOption(4);

      Xrm.Page.getControl('new_accounttype').removeOption(5);

      Xrm.Page.getControl('new_accounttype').removeOption(6);

      Xrm.Page.getControl('new_accounttype').removeOption(7);

       }

       else if (formName == "Account - Site") {

           Xrm.Page.getControl('new_accounttype').removeOption(1);

           Xrm.Page.getControl('new_accounttype').removeOption(2);

           Xrm.Page.getControl('new_accounttype').removeOption(6);

      Xrm.Page.getControl('new_accounttype').removeOption(7);

      }

      else if (formName == "Account - Distributor") {

           Xrm.Page.getControl('new_accounttype').removeOption(1);

           Xrm.Page.getControl('new_accounttype').removeOption(2);

           Xrm.Page.getControl('new_accounttype').removeOption(3);

      Xrm.Page.getControl('new_accounttype').removeOption(4);

       }

    }

    Thanks for your help guys!

  • Community Member Profile Picture
    on at
    RE: Show different values in for a single option set field

    Hi,

    I have tried else if too and it still gives me a scripting error.

    I also tried adding the header prefix since the field is in the header but it still gives me an error.

    Thanks

  • Verified answer
    Community Member Profile Picture
    on at
    RE: Show different values in for a single option set field

    Hi,

    it your last condition either you write else{....}

    or you write else if(formName == 'Account - Distributor'){...}

  • Community Member Profile Picture
    on at
    RE: Show different values in for a single option set field

    Ive been scratching my head over this for a while now but its giving me a script error. This is my code:

    function agentTypeOptionSetLoad() {

      var formName = Xrm.Page.ui.formSelector.getCurrentItem().getLabel();

      if (formName == 'Account - Organization') {

          Xrm.Page.getControl('new_accounttype').removeOption(3);

          Xrm.Page.getControl('new_accounttype').removeOption(4);

    Xrm.Page.getControl('new_accounttype').removeOption(5);

    Xrm.Page.getControl('new_accounttype').removeOption(6);

    Xrm.Page.getControl('new_accounttype').removeOption(7);

      }

      else if (formName == 'Account - Site') {

          Xrm.Page.getControl('new_accounttype').removeOption(1);

          Xrm.Page.getControl('new_accounttype').removeOption(2);

          Xrm.Page.getControl('new_accounttype').removeOption(6);

    Xrm.Page.getControl('new_accounttype').removeOption(7);

    }

    else (formName == 'Account - Distributor') {

          Xrm.Page.getControl('new_accounttype').removeOption(1);

          Xrm.Page.getControl('new_accounttype').removeOption(2);

          Xrm.Page.getControl('new_accounttype').removeOption(3);

    Xrm.Page.getControl('new_accounttype').removeOption(4);

      }

    }

    Im getting a scripting error. Please help.

    Thanks!

  • Suggested answer
    Community Member Profile Picture
    on at
    RE: Show different values in for a single option set field

    Hi,

    here are some useful link to help you out:

    community.dynamics.com/.../195852

    community.dynamics.com/.../223016

    community.dynamics.com/.../187171

  • Verified answer
    Venkata Ravi Babu Vakalapudi Profile Picture
    80 on at
    RE: Show different values in for a single option set field

    On onload of form you have to write a javascript to remove options based on form. You can use below code snippet.

    function agentTypeOptionSetLoad() {

       var formName = Xrm.Page.ui.formSelector.getCurrentItem().getLabel();

       if (formName == 'formA') {

           Xrm.Page.getControl('accountType').removeOption(4);

           Xrm.Page.getControl('accountType').removeOption(5);

       }

       else if (formName == "formB") {

           Xrm.Page.getControl('accountType').removeOption(1);

           Xrm.Page.getControl('accountType').removeOption(2);

           Xrm.Page.getControl('accountType').removeOption(3);

       }

    }

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