Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Answered

check.getSelectedOption is not a function

(0) ShareShare
ReportReport
Posted on by 82

Hi All 

After upgrading to the unified interface i am getting an error on one of the entities that check.getSelectedOption is not a function .

According to Microsoft some client APIs  are deprecated on my code I changed the Xrm.Page as it has been replaced by  ExecutionContext.getFormContext

Current code -  I get an error check.getSelectedOption                                                                  Replaced withExecutionContext.getFormContext  I get an Exexcution Context is not afunction error                                

function manq()                                                                                                                                                                     
{
var check= Xrm.Page.getAttribute("kb_mandatoryquestion");
if(check!=null)
{
var check2=check.getSelectedOption().value;
if(check2==1)
{Xrm.Page.getControl("kb_answer").removeOption(108630000); }
}
}

function critques()
{
var check= Xrm.Page.getAttribute("kb_criticalquestion");
if(check!=null)
{
var check2=check.getSelectedOption().value;
if(check2==1)
{
// Xrm.Page.getControl("kb_answer").removeOption(108630000);
Xrm.Page.getControl("kb_answer").removeOption(108630002);
}
}
}

function includescore()
{
var check = Xrm.Page.getAttribute("kb_includeinmaxscore");
if (check=="No")
{
Xrm.Page.getAttribute("kb_includescore").setValue(0) //set value to NoReplacement-1.PNGReplacement-2-.PNG
}
}

I have attached my resolutions with no luck how can i fix the above code according to Microsoft standards  iam getting a new error Exexcution Context is not a function error   

https://docs.microsoft.com/en-us/power-platform/important-changes-coming#some-client-apis-are-deprecated

  • rodzmaz81 Profile Picture
    82 on at
    RE: check.getSelectedOption is not a function

    Hi Miguel

    Will do.

  • Verified answer
    Miguel Lourenco Profile Picture
    on at
    RE: check.getSelectedOption is not a function

    Perfect, Happy to know it resolved.

    Don't forget to marked it as answered

    If by any chance you find any problem let me know

  • rodzmaz81 Profile Picture
    82 on at
    RE: check.getSelectedOption is not a function

    I meant to say thank you so much you are a star.

    After my testing I will update the call .

  • rodzmaz81 Profile Picture
    82 on at
    RE: check.getSelectedOption is not a function

    Hi Miguel

    I want to say thank you for your help the error is gone .

    I am just going to do an end to end testing to ensure Iam 100% sorted .

    I just want to thank you for help and patience you have been amazing my friend that you so much you are a Star!

  • Verified answer
    Miguel Lourenco Profile Picture
    on at
    RE: check.getSelectedOption is not a function

    Hi,

    the field kb_mandatoryquestion is a "two options" not an optionset.

    The same for the kb_criticalquestion field.

    Please copy paste this and try again:

    function manq()
    {
    var check= Xrm.Page.getAttribute("kb_mandatoryquestion");
    if(check!=null)
      {
    debugger;
       var check2=check.getValue();
          if(check2==1)
            {Xrm.Page.getControl("kb_answer").removeOption(108630000); }
      }
    }
    
    function critques()
    {
    var check= Xrm.Page.getAttribute("kb_criticalquestion");
    if(check!=null)
      {
    debugger;
        var check2=check.getValue();
          if(check2==1)
            {
    //          Xrm.Page.getControl("kb_answer").removeOption(108630000);
              Xrm.Page.getControl("kb_answer").removeOption(108630002); 
            }
         }
       } 
    

    I've replaced 

    var check2=check.getSelectedOption().value;

    with

    var check2=check.getValue();

    and the same for the kb_criticalquestion field.

    I didn't touch in your last function includescore as I didn't see any error.

  • Verified answer
    Miguel Lourenco Profile Picture
    on at
    RE: check.getSelectedOption is not a function

    let me check if I can help you

  • rodzmaz81 Profile Picture
    82 on at
    RE: check.getSelectedOption is not a function

    Hi

    The ticket number is 120032524001680 || check.getSelectedOption is not a function

    below is the details from Mahesh

    Greetings for the day,

    We have verified from our end and could see “XRM.Page” client API have been using in the script, this API have Deprecated in the UCI.

    Below is screen shot for your reference.

    Please use new replacement API to overcome this issue, below are the URL’s.

    Client API Reference for model-driven apps, below is the URL

    docs.microsoft.com/.../reference

    Some client APIs are deprecated with new replacement Client API, below is the URL

    docs.microsoft.com/.../important-changes-coming

    This is the current syntax on production and working  if this can be corrected it should work on the Unified Interface

    function manq()

    {

    var check= Xrm.Page.getAttribute("kb_mandatoryquestion");

    if(check!=null)

     {

      var check2=check.getSelectedOption().value;

         if(check2==1)

           {Xrm.Page.getControl("kb_answer").removeOption(108630000); }

     }

    }

    function critques()

    {

    var check= Xrm.Page.getAttribute("kb_criticalquestion");

    if(check!=null)

     {

       var check2=check.getSelectedOption().value;

         if(check2==1)

           {

    //          Xrm.Page.getControl("kb_answer").removeOption(108630000);

             Xrm.Page.getControl("kb_answer").removeOption(108630002);

           }

        }

      }

    function includescore()

    {

    var check = Xrm.Page.getAttribute("kb_includeinmaxscore");

    if (check=="No")

    {

    Xrm.Page.getAttribute("kb_includescore").setValue(0) //set value to No

    }

    }

  • Suggested answer
    Miguel Lourenco Profile Picture
    on at
    RE: check.getSelectedOption is not a function

    what is the ticket number?

  • rodzmaz81 Profile Picture
    82 on at
    RE: check.getSelectedOption is not a function

    Hi

    yes it is this is working perfectly on our production environment ,but we have transitioned the development environment to the Unified interface since then I am getting the error and just to add on that when I change the code i see the error changes meaning that is the issue.I have logged a support call with Microsoft who have advised to change the Xrm.page

  • Miguel Lourenco Profile Picture
    on at
    RE: check.getSelectedOption is not a function

    Anyway, just because it is deprecated doesn't mean it shouldn't work so believe the problem isn't related with this.

    Are you sure the kb_criticalquestion field is present in the form?

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 365 | Integration, Dataverse, and general topics

#1
Siv Sagar Profile Picture

Siv Sagar 149 Super User 2025 Season 1

#2
Muhammad Shahzad Shafique Profile Picture

Muhammad Shahzad Sh... 61 Most Valuable Professional

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

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

Overall leaderboard

Product updates

Dynamics 365 release plans