locked
How do I Create the OptionSet.cs File RRS feed

  • Question

  • I'm a bit new to CRM C# Developement, but I have successfully run the CrmSvcUtil.exe utility to generate the C# file containing all of our Entity classes and used that file in code.  

    Some of the SDK sample code includes a OptionSet.cs file that is also generated and contains option set enumerations for the default CRM entities. 

    My question is, how is this file generated as we need one that includes our custom option sets (enumerations). 

    Sunday, May 27, 2012 1:40 AM

Answers

  • Kahuna, try the second one, i.e. Organization Service URL. It did work for me.

    The ^ in a batch file allows you to have one long command distributed to multiple lines. You are still subjected to the 8k character limit but that won't be an issue in this case.

    • Marked as answer by Kahuna2000 Tuesday, May 29, 2012 2:33 PM
    Sunday, May 27, 2012 5:52 PM

All replies

  • Kahuna,

    The file generated by the CrmSvcUtlil.exe already has Custom option sets too. Please have a look at it again and update us.

    Thanks.


    Software developer working on Asp.Net, C#, jQuery and Dynamics CRM

    Sunday, May 27, 2012 4:02 AM
  • Hi,

    I did a blog post on this a while a go:

    http://www.develop1.net/public/post/Generate-Early-Bound-OptionSet-enums.aspx

    Hth,

    Scott


    Scott Durow
    Read my blog: www.develop1.net/public
    If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"

    Sunday, May 27, 2012 6:49 AM
    Answerer
  • I have a generateCode.bat file that I run to generate the code. %~dp0 is the location where the batch file is. You will have to adjust the relative paths for our project. You also have to adjust the url, username, and password inputs.

    cd %~dp0\..\..\..\sdk\samplecode\cs\crmsvcutilextensions\generatepicklistenums\bin\Debug
    CrmSvcUtil.exe ^
    /codewriterfilter:"Microsoft.Crm.Sdk.Samples.FilteringService, GeneratePicklistEnums" ^
    /codecustomization:"Microsoft.Crm.Sdk.Samples.CodeCustomizationService, GeneratePicklistEnums" ^
    /namingservice:"Microsoft.Crm.Sdk.Samples.NamingService, GeneratePicklistEnums" ^
    /url:https://[YourOrg].api.crm.dynamics.com/XRMServices/2011/Organization.svc ^
    /out:%~dp0\Xrm\OptionSets.cs ^
    /namespace:Xrm.OptionSets ^
    /username:... /password:....

    Additions Comments:

    * If you run crmsvutil only once then obviously a batch file is not necessary. In this case remove the first line starting with 'cd' and just go to the directory where the crmSvcUtil file is.

    * If you don't run this in a batch file then put everything on one line, i.e. without the ^ [Newline]

    * I have my early bound classes in the namespace Xrm and options sets in Xrm.OptionSets. Obviously you can change that to whatever your needs are.

    * To find the discovery url, in your CRM navigate to Settings (bottom left) -> Customization -> Customizations -> Developer Resources

    Sunday, May 27, 2012 7:16 AM
  • Zohaib,

    The file generated by the CrmSvcUtlil.exe only generates the State (e.g. Active/Inactive enums).

    Sunday, May 27, 2012 1:46 PM
  • Scott,

    This is a big help.  I also found a ReadMe doc in the SDK samples with some instructions.

    Unfortunately, when I make the mods in the bat file as follows:

    CrmSvcUtil.exe ^
    /codewriterfilter:"Microsoft.Crm.Sdk.Samples.FilteringService, GeneratePicklistEnums" ^
    /codecustomization:"Microsoft.Crm.Sdk.Samples.CodeCustomizationService, GeneratePicklistEnums" ^
    /namingservice:"Microsoft.Crm.Sdk.Samples.NamingService, GeneratePicklistEnums" ^
    /url:https://<my org>.crm.dynamics.com ^
    /out:MyOptionSets.cs 

    it does not run (or course <my org> is replaced with the real org in code) buts ends as follows:

    I would appreciate some help resolving this.

    Thanks.

    Sunday, May 27, 2012 2:11 PM
  • Kahuana2000, please check the url part from my previous post. It also describes where to find the correct URL.
    Sunday, May 27, 2012 4:14 PM
  • OK, MSFC, I looked it up.  It says:

    https://dev.crm.dynamics.com/XRMServices/2011/Discovery.svc

    Are you saying I should use this for the \url: parameter?

    That would certainly be different than what works for the regular CrmSvcUtil.exe URL.

    or should it be as in your code:

    /url:https://[YourOrg].api.crm.dynamics.com/XRMServices/2011/Organization.svc ^

    BTW are the "^" chars some kind of BAT file escape for Newline?

    Thanks for your help.

    Sunday, May 27, 2012 5:28 PM
  • Kahuna, try the second one, i.e. Organization Service URL. It did work for me.

    The ^ in a batch file allows you to have one long command distributed to multiple lines. You are still subjected to the 8k character limit but that won't be an issue in this case.

    • Marked as answer by Kahuna2000 Tuesday, May 29, 2012 2:33 PM
    Sunday, May 27, 2012 5:52 PM
  • Hi,

    Did you get this sorted - or are you still having problems?

    Scott


    Scott Durow
    Read my blog: www.develop1.net/public
    If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"

    Monday, May 28, 2012 3:43 PM
    Answerer
  • Thanks Scott and MSFC,

    I finally got this going with MSFC's URL.  I had to add a User and Password parameter to get the authentication also.

    K2K

    Tuesday, May 29, 2012 2:35 PM
  • Great - thanks for letting us know.

    Scott


    Scott Durow
    Read my blog: www.develop1.net/public
    If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"

    Tuesday, May 29, 2012 4:17 PM
    Answerer
  • Scott, I followed the directions on your blog at http://www.develop1.net/public/post/Generate-Early-Bound-OptionSet-enums.aspx and, with the addition of my userid id, password and domain, I was able to generate an OptionSets.cs file.

    However, when I looked at its contents, it did not contain any of the custom picklists.  Can you advice me on how to proceed?

    Thursday, January 9, 2014 3:40 PM