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 365 | Integration, Dataverse...
Answered

check.getSelectedOption is not a function

(0) ShareShare
ReportReport
Posted on by 84

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

I have the same question (0)
  • Suggested answer
    Miguel Lourenco Profile Picture
    on at

    Hi Rodzman,

    If you're using executioncontext you need to set it as a parameter:

    function hi(executionContext)

    {

    //do stuff

    }

    Also, you need to check this:

    pastedimage1585918310502v1.png

  • Suggested answer
    meelamri Profile Picture
    13,216 User Group Leader on at

    As said by Miguel Lourenco you should pass the execution as a parameter to your functions. Also, you have to use the formContext in your function you should get something like:

    var formContext = executionContext.getFormContext();

    var fieldName = formContext.getControl('fieldName').getAttribute();

    var fieldValue = fieldName.getValue(); //formContext.getAttribute('fieldName').getValue();

  • Miguel Lourenco Profile Picture
    on at

    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?

  • rodzmaz81 Profile Picture
    84 on at

    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

  • Suggested answer
    Miguel Lourenco Profile Picture
    on at

    what is the ticket number?

  • rodzmaz81 Profile Picture
    84 on at

    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

    }

    }

  • Verified answer
    Miguel Lourenco Profile Picture
    on at

    let me check if I can help you

  • Verified answer
    Miguel Lourenco Profile Picture
    on at

    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.

  • rodzmaz81 Profile Picture
    84 on at

    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!

  • rodzmaz81 Profile Picture
    84 on at

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

    After my testing I will update the call .

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

#1
Siv Sagar Profile Picture

Siv Sagar 93 Super User 2025 Season 2

#2
#ManoVerse Profile Picture

#ManoVerse 76

#3
Martin Dráb Profile Picture

Martin Dráb 64 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans