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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Answered

I'm getting error while saving the details

(0) ShareShare
ReportReport
Posted on by 5

I wrote a code for getting multi select options for security role while selecting specific records and saving the details I'm getting this error.

One or more of the option values for this picklist are not in the range of allowed values.

My code:

function getRole(executionContext)
{
debugger;
var fetchXml = "?fetchXml=<fetch mapping='logical'><entity name='role'><attribute name='roleid'/><attribute name='name'/></entity></fetch>";
Xrm.WebApi.retrieveMultipleRecords("role", fetchXml).then(
function success(result) {
var formContext=executionContext.getFormContext();
var optionCode=formContext.getControl("gab_securityrole");
//optionCode.clearOptions();
var optionKey=10000;
for (var i=0;i<result.entities.length;i++) {
var Name=result.entities[i].name;
var obj={};
obj["text"]=Name;
obj["value"]=optionKey;
optionCode.addOption(obj);
optionKey++;
}
},
function (error){
alert(error.message);
}
)
};

Please do respond to my query

  • Verified answer
    Bipin D365 Profile Picture
    28,995 Moderator on at

    Hi,

    Do you have multiple Business unit in your system?

    If yes then you will get duplicate role name for each BU.

    For example Role name is salesperson and BU is Bu1 &BU2

    So in your results you will see two record .

    You should modify your fetchXml to add filter condition for Business Unit

    Try running fetchXml in advanced find to see the result for yourself

  • Divya Mahanthi Profile Picture
    5 on at

    I'm very new to this can u tell me where can I find the fetch Xml?

  • Verified answer
    Bipin D365 Profile Picture
    28,995 Moderator on at

    Hi,

    fetchXml is in your code.

    To add business unit filter and test fetchXml you can use fetchXml builder tool in xrmtoolbox

    https://fetchxmlbuilder.com/

    You can also use Dataverse rest builder tool

    carldesouza.com/.../

  • Verified answer
    Bipin D365 Profile Picture
    28,995 Moderator on at

    Hi,

    You can open advanced find and design your query as below

    IMG20221021172251.jpg

    Then you can download fetchXml by clicking on Download fetchXml button on top

    Use this fetchXml in your javascript code

  • Divya Mahanthi Profile Picture
    5 on at

    can you rectify the code and send it to me im using this java script in form properties so I dont have any idea about this tools please do help me with this

  • Suggested answer
    Bipin D365 Profile Picture
    28,995 Moderator on at

    Hi,

    As discussed on call, your multi select optionset field does not have any option added.

    Your javascript code will work only when you have option added .

    If you want to add option to your multi optionset then you can write one time console application using c# to dynamically add option.

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
11manish Profile Picture

11manish 91 Super User 2026 Season 2

#2
Travis South Profile Picture

Travis South 71

#3
Daniyal Khaleel Profile Picture

Daniyal Khaleel 52 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans