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 :
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

I have the same question (0)
  • Verified answer
    Venkata Ravi Babu Vakalapudi Profile Picture
    80 on at

    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);

       }

    }

  • Suggested answer
    Community Member Profile Picture
    on at

    Hi,

    here are some useful link to help you out:

    community.dynamics.com/.../195852

    community.dynamics.com/.../223016

    community.dynamics.com/.../187171

  • Community Member Profile Picture
    on at

    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!

  • Verified answer
    Community Member Profile Picture
    on at

    Hi,

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

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

  • Community Member Profile Picture
    on at

    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

    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!

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 > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans