locked
optionset so complicated !!!! RRS feed

  • Question

  • I'm trying to get the text from an option set in CRM 2015 Online. I need to obtain Payment Terms Code from Quotes.

    I'm using XRM from c#, so to get the value from an optio nset I use: Quote.PaymentTermsCode.Value, but with this option I get the value of the index in the option set, but what I need to get is the text. It's so complicate to put a method that says "Text" or "getText" ?????

    I read something about Xrm.page, but I access CRM using xrm, so I can't use Javascript.

    I read something to create some methods GetOptionsetText using  IOrganizationService, but it's complicated.

    Why not a text or getText method???

    There are not an easy option?

    Thanks


    santiago

    Monday, June 22, 2015 4:06 PM

All replies

  • I agree, it can be complicated.  Have you tried the FormattedValues object?  For a Quote you referenced, it would be something like.

    string x = Quote.FormattedValues["paymenttermscode"];

    I think this only works if you have the classes for your CRM created by the CrmSvcUtil, but it's a lot simpler that trying to query the metadata.

    Good Luck!

    Tuesday, June 23, 2015 1:16 PM
  • FormattedValues works also with late bound (so without the classes generated by CrmSvcUtil)

    If your organization use only the base language and you code is not running in a strange place (like an update plugin) you can use FormattedValues.


    My blog: www.crmanswers.net - CRM Theme Generator

    Tuesday, June 23, 2015 1:50 PM
  • Chris,

    It doesn't work:

    If I try this: string x = Quote.FormattedValues["FreightTermsCode"];

    appears this error: The key provided was not found in the dictionary.

    but If I try this: int envio = Quote.FreightTermsCode.Value;

    It works, so the key "FreightTermsCode" exists in the dictionary, so Why FormattedValues doesn't work?

    Thanks




    santiago

    Tuesday, July 7, 2015 1:57 PM
  • Keys are case sensitive...so it has to be all lower case.  Give that a try and let us know if that works.

    string x = Quote.FormattedValues["freighttermscode"];

    Tuesday, July 7, 2015 2:08 PM
  • because you need to write it lowercase

    string x = Quote.FormattedValues["freighttermscode"];
    


    My blog: www.crmanswers.net - CRM Theme Generator

    Tuesday, July 7, 2015 2:09 PM