Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Dynamics 365 general forum

JavaScript Not Working in Unified Interface - Adding Options to Multi Select Option Set

(1) ShareShare
ReportReport
Posted on by 110

Hello,


We are trying to programatically add options to a multi select option set in Dynamics 365, using JavaScript.

The below code snippet works fine in the old web interface, but in the Unified Interface we are getting the following error:

TypeError: Xrm.OptionSetItem is not a constructor

Has anyone enountered this issue before and knows a workaround? In this scenario we are unable to remove select options in the code, due to the amount of options available.

This also begs the question, do certain JavaScript methods only work in the old web client?

function filterOptionSet(executionContext) {
try {

'
var formContext = executionContext.getFormContext(); // get formContext
var optionSetCtrl = formContext.getControl("evo_subsectors");
var industryObj = formContext.getAttribute("evo_industrysector");
console.log("Industry field is: " + industryObj);
//Clear all options
optionSetCtrl.clearOptions();
if (industryObj != null) { //Check if industry field is empty
switch (industryObj.getValue()) {
case 914060005: //If industry is this value (Emergency Services)
console.log("Emergency services sub sectors here")
optionSetCtrl.addOption(new Xrm.OptionSetItem(914060001,"Police"), 0) //(value-int, text-string), position-integer)
optionSetCtrl.addOption(new Xrm.OptionSetItem(914060002,"Coast Guard"), 1)
optionSetCtrl.addOption(new Xrm.OptionSetItem(914060003,"Private Ambulance Services"), 2)
optionSetCtrl.addOption(new Xrm.OptionSetItem(914060000,"Fire Service"), 3)
break;
case 914060007: //Or, if industry is this value (Education)
optionSetCtrl.addOption(new Xrm.OptionSetItem(914060004,"Nursery"), 0)
optionSetCtrl.addOption(new Xrm.OptionSetItem(914060005,"Schools and Colleges"), 1)
optionSetCtrl.addOption(new Xrm.OptionSetItem(914060006,"Higher and Further Education"), 2)
optionSetCtrl.addOption(new Xrm.OptionSetItem(914060007,"Specialist Education Establishment"), 3)
break;
Categories:
  • Suggested answer
    Gibran Profile Picture
    35 on at
    RE: JavaScript Not Working in Unified Interface - Adding Options to Multi Select Option Set

    You can do the following >

    var label = "something ";

    var value = "9000001";

    var xrmOptions = null ;

    if (Xrm.Internal.isUci()) {

                           xrmOptions = {

                               "text": label.trim(),

                               "value": value.trim())

                           };

    }

    else {

                           xrmOptions = new Xrm.OptionSetItem(label.trim(), value.trim());

    }

    optionSetCtrl.addOption(xrmOptions, [position value])

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

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 294,095 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 232,866 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,158 Moderator

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans