I was creating a new entity and trying to fill in the default values for it and then use the
serviceProxy.Create method to add the new entity.
one of the entities had an OptionSet as a business required. I tried searching for this but couldn’t find much and in the end I managed to work it out myself.
When you set an OptionSetValue you need to create a new one. One of the problems I had was I because I was using Early Binding the values are set as null, so I couldn’t work out what it should be by looking at an example.
OptionSetValue option = new OptionSetValue(143570000);
The important thing you need to consider is the value is the value on the optionSet and its not very likely to be 1, 2, 3. If you have created the optionSet yourself the default values are 140000000 or something huge like that.
I had to look on the form to find the value but then once you have made the new option set you can either add it directly to the entity
newCan.hosk_ContactPreference = option;
or if you are using the Entity you need to add it as an attribute
Entity ent = new Entity();