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

Notifications

Announcements

No record found.

Community site session details

Community site session details

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

How to set optionset value as selected using JS

(0) ShareShare
ReportReport
Posted on by 10

Hello all,

This is my issue : 

When a user selects an option for which he does not have the authorizations, an error message appears as an alert (it's okay up here).

Then, I would like another optionset to be selected to replace the one the user has chosen. 

Optionset-issue.jpg

This is the codes I have tried but that didn't work for me : 

Xrm.Page.getAttribute("NameOfMyField").setValue(null); //Here I have even tried to replace the null value by the one of another optionset like ("860330002") but unsuccessfull

I've tried as well : Xrm.Page.Data.Entity.Attributes.Get("nameofmyfield").setValue(null); //Did not work for me as well

Need support ASAP to solve an issue for a customer. 

Thanks 

I have the same question (0)
  • Verified answer
    Bipin D365 Profile Picture
    28,983 Moderator on at

    Hi,

    Can you please try setting -1 value as below

    Xrm.Page.getAttribute("NameOfMyField").setValue(-1);

    Since you are on CRM Online then why don't you use formcontext instead of Xrm.Page because Xrm.Page is deprecated.

  • RaphaelMG Profile Picture
    10 on at

    Hi Bipin Kumar

    Thanks for your update. I've tried using setValue(-1) as you suggested me but it did not work.

    I found out that by removing the alert() function from the code (which warns the user that he doesn't have the right to make this change),  everything works fine.

    I don't understand how this could block the normal execution of the function shared above : Xrm.Page.Data.Entity.Attributes.Get("nameofmyfield").setValue(null);

    Since there was an urgency to unblock the client and it worked, I can look into your recommendation to use formcontext and do some testing, Since the user must have a warning message.

    Thanks for your feedback

  • Suggested answer
    Abdul Wahab Profile Picture
    12,119 Moderator on at

    Hi RaphaelMG,

    write the below lines to set the value:

    formContext.getAttribute("NameOfMyField").setSubmitMode("always");//details

    formContext.getAttribute("NameOfMyField").setValue(value);// details.

    formContext.data.save().then(successCallback, errorCallback);//details

    Abdul Wahab
    Power Platform/Customer Engagement Developer/Lead/Solution Architecture/Project Manager
    Direct/WhatsApp:+923323281237
    E-mail: abdulwahabubit@outlook.com
    Skype: abdul.wahabubit

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

    Hi,

    So you need to first set null value then show warning message.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 170 Super User 2025 Season 2

#2
#ManoVerse Profile Picture

#ManoVerse 70

#3
Jimmy Passeti Profile Picture

Jimmy Passeti 50 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans