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

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

API reference error

(0) ShareShare
ReportReport
Posted on by 1,942

Hey All,

I am using the following code to set the value of an option set field based on the input values from a multi option set field. I receive the error saying "TypeError: formContext.getAttribute(...).SetValue is not a function at SetMultiSelValues "

Error Log:

TypeError: formContext.getAttribute(...).SetValue is not a function
at SetMultiSelValues (ssgrp.crm8.dynamics.com/.../new_MultipOptionset)
at eval (eval at RunHandlerInternal (ssgrp.crm8.dynamics.com/.../ClientApiWrapper.aspx), <anonymous>:1:1)
at RunHandlerInternal (ssgrp.crm8.dynamics.com/.../ClientApiWrapper.aspx)
at RunHandlers (ssgrp.crm8.dynamics.com/.../ClientApiWrapper.aspx)
at OnScriptTagLoaded (ssgrp.crm8.dynamics.com/.../ClientApiWrapper.aspx)
at https://ssgrp.crm8.dynamics.com/form/ClientApiWrapper.aspx?ver=-269532236:202:1

Javascript Code: 

function SetMultiSelValues(executionContext)
{
debugger;
var formContext = executionContext.getFormContext();
var selectedValues = formContext.getAttribute("new_flagreason").getSelectedOption();
var selectedOptionText = formContext.getAttribute("new_flagreason").getText();
if(selectedValues != null){
if(selectedValues != 100000000){
formContext.getAttribute("new_flagstatus").SetValue("100000000");
}
else{
formContext.getAttribute("new_flagstatus").SetValue("100000001");
}
}
}

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Alex Fun Wei Jie Profile Picture
    33,626 on at
    RE: API reference error

    Hi,

    change the below part 

    1. SetValue(100000000); to setValue(100000000); 

    2. SetValue(100000001); to setValue(100000001); 

  • Suggested answer
    Alex Fun Wei Jie Profile Picture
    33,626 on at
    RE: API reference error

    Hi,

    you can refer below article for more information about the syntax of client side script

    docs.microsoft.com/.../setvalue

  • Suggested answer
    Shahbaaz Ansari Profile Picture
    6,211 on at
    RE: API reference error

    Hi Vighnesh,

    try to set the optionset value like

    Xrm.Page.getAttribute(optionsetAttribute).setValue(intOptionSetValue);

    Xrm.Page.getAttribute("new_flagstatus").setValue(100000000);

    Check this link,

    community.dynamics.com/.../144399

    Thanks,

    Shahbaaz

  • Vighnesh Profile Picture
    1,942 on at
    RE: API reference error

    You are correct Wei!

    It was a syntax mistake.

    Thanks a lot

  • Vighnesh Profile Picture
    1,942 on at
    RE: API reference error

    I have to update the field which is located on header and i used the syntax with header_new_flagstatus. But then i again receive the error "ReferenceError: formContext is not defined↵    at eval (eval at RunHandlerInternal 

  • Suggested answer
    Shahbaaz Ansari Profile Picture
    6,211 on at
    RE: API reference error

    Hi GVR,

    Try below code, "header_new_flagreason"

    Xrm.Page.getAttribute("header_new_flagreason").setValue(intOptionSetValue);

    Thanks,

    Shahbaaz

  • Vighnesh Profile Picture
    1,942 on at
    RE: API reference error

    That didn't work Shahbaaz.

  • Suggested answer
    Shahbaaz Ansari Profile Picture
    6,211 on at
    RE: API reference error

    Hi GVR,

    It should work without "header" try using

    var formContext = executionContext.getFormContext();

    formContext.getAttribute("new_flagstatus").setValue("100000000");

    Thanks,

    Shahbaaz

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
HR-09070029-0 Profile Picture

HR-09070029-0 2

#1
UllrSki Profile Picture

UllrSki 2

#3
ED-30091530-0 Profile Picture

ED-30091530-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans