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

Notifications

Announcements

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:
I have the same question (0)
  • Suggested answer
    Gibran Profile Picture
    35 on at

    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

News and Announcements

Season of Giving Solutions is Here!

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 > Dynamics 365 general

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans