GetValidReferencingEntities Message (MetadataService)
![]() |
[Applies to: Microsoft Dynamics CRM 4.0]
Find the latest SDK documentation: CRM 2015 SDK
| Works for all deployment types | Works online only |
Returns the set of entities that are valid as the related entity (many) to the specified entity in a one-to-many relationship.
The relevant classes are specified in the following table.
| Type | Class |
| Request | GetValidReferencingEntitiesRequest |
| Response | GetValidReferencingEntitiesResponse |
Remarks
If no entity is specified, this message returns all entities that can be the related entity in a one-to-many relationship.
To perform this action, the caller must be a user in the organization for which metadata is requested and must have Read Attribute, Read Entity and Read Relationship privileges.
Example
The following example shows how to use the GetValidReferencingEntities message.
[C#]
// Create an authentication token.
CrmAuthenticationToken token = new CrmAuthenticationToken();
token.OrganizationName = "AdventureWorksCycle";
// You can use enums.cs from the SDK\Helpers folder to get the enumeration for Active Directory authentication.
token.AuthenticationType = 0;
// Create the metadata Web service;
MetadataService metadataService = new MetadataService();
metadataService.Url = "http://<servername>:<port>/MSCRMServices/2007/MetadataService.asmx";
metadataService.CrmAuthenticationTokenValue = token;
metadataService.Credentials = System.Net.CredentialCache.DefaultCredentials;
metadataService.PreAuthenticate = true;
// Create the request.
GetValidReferencingEntitiesRequest validRelatedEntitiesRequest = new GetValidReferencingEntitiesRequest();
validRelatedEntitiesRequest.ReferencedEntityName = EntityName.account.ToString();
// Execute the request.
GetValidReferencingEntitiesResponse validRelatedEntitiesResponse = (GetValidReferencingEntitiesResponse)metadataService.Execute(validRelatedEntitiesRequest);
// Print all valid entities
foreach (string validEntity in validRelatedEntitiesResponse.EntityNames)
{
Console.WriteLine("Valid Related Entity: " + validEntity);
}
[Visual Basic .NET]
' Set up the CRM Service.
Dim token As New CrmAuthenticationToken()
' You can use enums.cs from the SDK\Helpers folder to get the enumeration for Active Directory authentication.
token.AuthenticationType = 0
token.OrganizationName = "AdventureWorksCycle";
// Create the metadata Web service.
Dim metadataService As New MetadataService ()
metadataService.Url = "http://<servername>:<port>/mscrmservices/2007/MetadataService.asmx";
metadataService.CrmAuthenticationTokenValue = token;
metadataService.Credentials = System.Net.CredentialCache.DefaultCredentials
metadataService.PreAuthenticate = true;
' Create the request.
Dim validRelatedEntitiesRequest As New GetValidReferencingEntitiesRequest()
validRelatedEntitiesRequest.ReferencedEntityName = EntityName.account.ToString()
' Execute the request.
Dim validRelatedEntitiesResponse As GetValidReferencingEntitiesResponse = CType(metadataService.Execute(validRelatedEntitiesRequest), GetValidReferencingEntitiesResponse)
' Print all valid entities.
For Each validEntity As String In validRelatedEntitiesResponse.EntityNames
Console.WriteLine("Valid Related Entity: " & validEntity)
Next validEntity
See Also
Concepts
Reference
.gif)