Answered by:
How to Copy Optin Set from One entity to another

Question
-
Dear All,
I have a Option set in LEad Entity with almost 70 options to select.
Now am designing a new Entity and i need the Same option to be in the New Entity.
It will be really a tedious job to create a new Option set in this new entity with all those 70 options .
Is there a way to just copy this option set field in to my new Entity.
Thanks
Friday, June 14, 2013 7:03 AM
Answers
-
Here you'll find my code as a tool : http://code.msdn.microsoft.com/Create-global-option-set-8a20eb95
Just fill in the required fields and hit the copy button.
Best regards
Steve
Steve Sämmang, Vienna, Austria
Blog: xrm.io Website: simplic.at- Proposed as answer by Parthiban.T Friday, June 14, 2013 9:18 AM
- Marked as answer by mc.gem Friday, June 14, 2013 11:46 AM
- Edited by saemmang Saturday, June 15, 2013 9:13 AM
Friday, June 14, 2013 9:01 AM
All replies
-
Hi ,
you can try Global Options set method which is available in CRM 2011.
Note : once you have created Global option set , you can use in any entity .
Refer bellow link.
http://pradeepranganath.wordpress.com/2011/06/08/ms-crm-2011-global-option-sets/
http://www.dynamicscrmtrickbag.com/2010/12/02/global-option-sets-in-dynamics-crm-2011/
- Proposed as answer by VidhiyaM Friday, June 14, 2013 7:25 AM
Friday, June 14, 2013 7:10 AM -
Hello,
As Parthiban said, you should use a global option set.
You can try to copy the option set via code. You have to read the existing ones metadata and create a new global one.
Here you'll find the code for creating an optionset:
http://msdn.microsoft.com/en-us/library/gg509056.aspx
Best regards
Steve Sämmang, Vienna, Austria
Blog: xrm.io Website: simplic.at- Proposed as answer by VidhiyaM Friday, June 14, 2013 7:25 AM
Friday, June 14, 2013 7:21 AM -
Hi,
Global option set will help you in that.Try this,
http://www.powerobjects.com/blog/2011/09/12/global-option-sets-in-dynamics-crm-2011/
http://ashishmahajancrm.wordpress.com/2012/02/04/crm-2011-global-option-sets-picklists/
VidhiyaM
- Proposed as answer by VidhiyaM Friday, June 14, 2013 7:25 AM
Friday, June 14, 2013 7:25 AM -
The following code should do the copy for you:
internal static void copyOptionSetToGlobal(string Entity,string Attribute,string NewOptionSetLabel,string NewOptionSetDisplayName,string NewOptionSetDescription,IOrganizationService Service,int LanguageCode = 1033) { RetrieveAttributeRequest retrieveAttributeRequest = new RetrieveAttributeRequest { EntityLogicalName = Entity, LogicalName = Attribute, RetrieveAsIfPublished = true }; RetrieveAttributeResponse retrieveAttributeResponse = (RetrieveAttributeResponse)Service.Execute(retrieveAttributeRequest); PicklistAttributeMetadata retrievedPicklistAttributeMetadata = (PicklistAttributeMetadata)retrieveAttributeResponse.AttributeMetadata; OptionMetadata[] optionList = retrievedPicklistAttributeMetadata.OptionSet.Options.ToArray(); OptionSetMetadata SetupOptionSetMetadata = new OptionSetMetadata() { Name = NewOptionSetLabel, DisplayName = new Label(NewOptionSetDisplayName,LanguageCode), Description = new Label(NewOptionSetDescription,LanguageCode), IsGlobal = true, OptionSetType = OptionSetType.Picklist, }; foreach(OptionMetadata oMD in optionList) { SetupOptionSetMetadata.Options.Add(oMD); } CreateOptionSetRequest createOptionSetRequest = new CreateOptionSetRequest { OptionSet = SetupOptionSetMetadata }; Service.Execute(createOptionSetRequest); }
To call this method:
IOrganizationService _service = GetOrganizationService(); copyOptionSetToGlobal("lead","new_attributename","new_globaloptionset","NEWOPTIONSETDISPLAY","DESCRIPTION",_service,1033);
Best regards
Steve
Steve Sämmang, Vienna, Austria
Blog: xrm.io Website: simplic.at
- Edited by saemmang Friday, June 14, 2013 7:41 AM
Friday, June 14, 2013 7:40 AM -
Hi Partiban and Saemmang,
Thanks for the Reply.
I already have a option set in the form.Now how can i convert to Global Option set.
thanks
Friday, June 14, 2013 8:27 AM -
Hi,
Follow these steps:
- Copy the existing (70 entries) option set to a global option set. This have do be done manually or by code (see my last answer)
- Add a new field to the new entity and choose the global option set as source for that picklist
You can run the code in a simple console application.
Best regards
Steve
Steve Sämmang, Vienna, Austria
Blog: xrm.io Website: simplic.atFriday, June 14, 2013 8:32 AM -
Here you'll find my code as a tool : http://code.msdn.microsoft.com/Create-global-option-set-8a20eb95
Just fill in the required fields and hit the copy button.
Best regards
Steve
Steve Sämmang, Vienna, Austria
Blog: xrm.io Website: simplic.at- Proposed as answer by Parthiban.T Friday, June 14, 2013 9:18 AM
- Marked as answer by mc.gem Friday, June 14, 2013 11:46 AM
- Edited by saemmang Saturday, June 15, 2013 9:13 AM
Friday, June 14, 2013 9:01 AM