Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

API reference error

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

  • Suggested answer
    Shahbaaz Ansari Profile Picture
    Shahbaaz Ansari 6,203 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

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

    That didn't work Shahbaaz.

  • Suggested answer
    Shahbaaz Ansari Profile Picture
    Shahbaaz Ansari 6,203 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
    Vighnesh 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 

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

    You are correct Wei!

    It was a syntax mistake.

    Thanks a lot

  • Suggested answer
    Shahbaaz Ansari Profile Picture
    Shahbaaz Ansari 6,203 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

  • Suggested answer
    Alex Fun Wei Jie Profile Picture
    Alex Fun Wei Jie 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

  • Verified answer
    Alex Fun Wei Jie Profile Picture
    Alex Fun Wei Jie 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); 

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans