Skip to main content

Notifications

Microsoft Dynamics CRM forum
Answered

I'm getting error while saving the details

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

  • Suggested answer
    Bipin D365 Profile Picture
    Bipin D365 28,962 Moderator on at
    RE: I'm getting error while saving the details

    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.

  • Divya Mahanthi Profile Picture
    Divya Mahanthi 5 on at
    RE: I'm getting error while saving the details

    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

  • Verified answer
    Bipin D365 Profile Picture
    Bipin D365 28,962 Moderator on at
    RE: I'm getting error while saving the details

    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

  • Verified answer
    Bipin D365 Profile Picture
    Bipin D365 28,962 Moderator on at
    RE: I'm getting error while saving the details

    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/.../

  • Divya Mahanthi Profile Picture
    Divya Mahanthi 5 on at
    RE: I'm getting error while saving the details

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

  • Verified answer
    Bipin D365 Profile Picture
    Bipin D365 28,962 Moderator on at
    RE: I'm getting error while saving the details

    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

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

Dynamics 365 Community Update – Sep 16th

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

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Dynamics 365 Community Newsletter - September 2024

Check out the latest community news

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,522 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,441 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans