SBX - Search With Button

SBX - Forum Post Title

How to set the option set value dynamically using javascript.

Microsoft Dynamics CRM Forum

Dilip Gawas asked a question on 10 Nov 2014 5:22 AM
My Badges

Question Status

Verified

How to set the option set value dynamically using javascript.  

I am using the code line is "Xrm.Page.data.entity.attributes.get("new_substage").setValue(100000000);"

but its not working.

thanks 

dilip

Reply
Guido Preite responded on 10 Nov 2014 5:33 AM
My Badges
Verified Answer

the code is correct, make sure that the integer value you pass is a valid one.

you can also use the short form:

Xrm.Page.getAttribute("new_substage").setValue(100000000);

Reply
Aileen Gusni responded on 10 Nov 2014 7:58 AM
My Badges
Verified Answer

Hi Dilip,

It seems Okay with your code, yes, just make sure your field name (lower caps) and the option set value are correct, and this is an Option Set, not Two Options, because if it is two option you need to give value true or false instead of the 100000000

And maybe you can try this:

Xrm.Page.getAttribute(optionsetAttribute).setValue(intOptionSetValue);

It is also the short form according to Guid's answer.

social.microsoft.com/.../what-is-the-difference-between-xrmpagedataentityattributesget-and-xrmpagegetattribute

Check your field option set value in the detailed field property

Thanks.

Reply
srinivascrm responded on 31 Jul 2015 10:46 PM

I am trying to set the firstnames to optionset using the below :

GetFirstname = Xrm.Page.getControl("new_firstname");
GetFirstname.addOption({ text: value.firstname, value: key });

The above is adding all the desired firstnames to the optionset. But, when I am selecting any firstname , it is not displayed .

Any help ?

Reply
Saddam Khan(Sam) responded on 9 Jun 2017 6:42 AM
My Badges
Suggested Answer

use this it will work

Xrm.Page.data.entity.attributes.get("statuscode").setValue(100000001);

Reply
Vipin Jaiswal responded on 22 May 2019 4:01 AM
My Badges
Suggested Answer

Here is a generic way to get optionset values in C#, Rest API Javascript and CRM Formscript

vjcity.blogspot.com/.../generic-way-to-get-optionset-value-or.html

Reply
Guido Preite responded on 10 Nov 2014 5:33 AM
My Badges
Verified Answer

the code is correct, make sure that the integer value you pass is a valid one.

you can also use the short form:

Xrm.Page.getAttribute("new_substage").setValue(100000000);

Reply
Aileen Gusni responded on 10 Nov 2014 7:58 AM
My Badges
Verified Answer

Hi Dilip,

It seems Okay with your code, yes, just make sure your field name (lower caps) and the option set value are correct, and this is an Option Set, not Two Options, because if it is two option you need to give value true or false instead of the 100000000

And maybe you can try this:

Xrm.Page.getAttribute(optionsetAttribute).setValue(intOptionSetValue);

It is also the short form according to Guid's answer.

social.microsoft.com/.../what-is-the-difference-between-xrmpagedataentityattributesget-and-xrmpagegetattribute

Check your field option set value in the detailed field property

Thanks.

Reply
Saddam Khan(Sam) responded on 9 Jun 2017 6:42 AM
My Badges
Suggested Answer

use this it will work

Xrm.Page.data.entity.attributes.get("statuscode").setValue(100000001);

Reply
Vipin Jaiswal responded on 22 May 2019 4:01 AM
My Badges
Suggested Answer

Here is a generic way to get optionset values in C#, Rest API Javascript and CRM Formscript

vjcity.blogspot.com/.../generic-way-to-get-optionset-value-or.html

Reply

SBX - Two Col Forum

SBX - Migrated JS