how to retrieve optionset value based on the text CRM 2011
-
donderdag 31 mei 2012 20:21
Hi, I need to retrieve the option set value based on the text in c# code. (CRM 2011 online)
if a matching optionset exist, I would like to retreive and apply to the field.
otherwise, I need to create a new optionset value.
Say, Rating in Lead entity has Hot, warm, cold;
I need to find a matching Rating optionset value if the text is Hot; <this text value is retrieved from a local SQL database)
Appreciate your help.
Alle reacties
-
vrijdag 1 juni 2012 4:29
Hi,
you may query the "FilteredStringMap" table and use the AttributeValue / Value to validate your text (eg. Hot). moreover in order to provide more filter to it you may use the AttributeName (this will be your optionset) and FilteredViewName (this will contain your entity name also to which option set is attached).
let me know in case you have any query.
Thanks,
Anubhav Bajpai
-
vrijdag 1 juni 2012 5:15Moderator
Hi,
My suggestion to use Iorganization service, to retrieve metada and compare your values if you not preset create that value. you should be able to find sample code in SDK
below are some post that will help you
http://guruprasadcrm.blogspot.in/2011/07/retrieving-optionset-lable-data-using.html
Conatact Me
Follow me on Twitter
Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.- Als antwoord voorgesteld door MubasherSharif vrijdag 1 juni 2012 8:04
-
vrijdag 1 juni 2012 6:37
Hi CRM Elite,
You can use the following code.
var request = new RetrieveAttributeRequest { EntityLogicalName = entityName, LogicalName = attributeName, RetrieveAsIfPublished = true }; var response = (RetrieveAttributeResponse)_organizationService.Execute(request); var picklist = (PicklistAttributeMetadata)response.AttributeMetadata; var thePicklist = picklist.OptionSet.Options.FirstOrDefault(i => i.Label.LocalizedLabels != null && i.Label.LocalizedLabels.Count > 0 && i.Label.LocalizedLabels[0].Label == "Hot"); var picklistValue = thePicklist == null ? -1 : thePicklist.Value;I hope this helps. If my response answered your question, please mark the response as an answer and also vote as helpful.
Dimaz Pramudya | CSG (Melbourne) | http://www.xrmbits.com | dimaz@xrmbits.com If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"
- Als antwoord voorgesteld door Dimaz Pramudya (www.xrmbits.com) vrijdag 1 juni 2012 6:37
-
vrijdag 1 juni 2012 13:19Thanks Dimaz, I will try your code. Just so I understand, you are using the attributeresponse to retrieve all the picklist metadata (along with it's value). What happens if I have say two different optionsets with similar text. Say, I have optionset1 that contains "Hot" as one of the text; Optionset2 also contains "Hot". Off-course the valuecode will be different. Assuming these two optionsets are local to a same-account.
-
maandag 4 juni 2012 23:38
Hi CRM Elite,
The way you differentiate between which optionset values to retrieve is based on the attribute schema name.
Eg: optionset1 might be called new_optionset1 and optionset2 might be called new_optionset2.
When you are constructing the RetrieveAttributeRequest, the "new_optionset1" is what you passed in to the LogicalName.
That way you will always get the correct optionsetvalue out of your text.
I hope this helps. If my response answered your question, please mark the response as an answer and also vote as helpful.
Dimaz Pramudya | CSG (Melbourne) | http://www.xrmbits.com | dimaz@xrmbits.com If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"
- Als antwoord voorgesteld door Dimaz Pramudya (www.xrmbits.com) maandag 4 juni 2012 23:38
- Bewerkt door Dimaz Pramudya (www.xrmbits.com) maandag 4 juni 2012 23:38