12.04.09

CRM 4 vb.net example of status description retrieval when one has just the integer id

Posted in Uncategorized at 3:40 pm by mmwebesa

‘This was used in a plugin hence the “IMetadataService” as a parameter in the function.
‘Otherwise, “MetadataService” would have been used instead.   
 Private Function GetCfstatusPicklistLabels(ByVal cfStatus As Integer, ByVal mdService As IMetadataService) As String

Dim cfStatusDesc As String = “” 

Dim cfStatusValue As Integer = 0
 Dim amd As AttributeMetadata

Dim attributeRequest As New RetrieveAttributeRequest

attributeRequest.EntityLogicalName = EntityName.appointment.ToString

attributeRequest.LogicalName = “cf_status” ‘attribute name

 Dim attributeResponse As RetrieveAttributeResponse

attributeResponse = CType(mdService.Execute(attributeRequest), RetrieveAttributeResponse)

amd = attributeResponse.AttributeMetadata
Dim pam As PicklistAttributeMetadata = CType(amd, PicklistAttributeMetadata)

 For Each pamOption As [Option] In pam.Options

cfStatusValue = cfStatus

If cfStatusValue = pamOption.Value.Value Then

cfStatusDesc = pamOption.Label.LocLabels(0).Label.ToString 
 Exit For
 End If
 Next
 Return cfStatusDesc

End Function



Leave a Comment