This documentation is archived and is not being maintained.

RemoveParent Message (CrmService)

banner art

[Applies to: Microsoft Dynamics CRM 4.0]

Find the latest SDK documentation: CRM 2015 SDK

Works for all deployment typesWorks online only

Removes the parent for an entity instance.

The relevant classes are specified in the following table.

EntitySee below.

The following table shows the entities and target classes for this message.

EntityTarget Class


To use this message, pass an instance of the RemoveParentRequest class as the request parameter in the Execute method.

The parent for an entity instance is set using the SetParentSystemUser message.

To perform this action, the caller must have access rights on the role entity instance. For a list of required privileges, see RemoveParent Privileges.


The following code example shows how to use the RemoveParent message.

// Set up the CRM service.
CrmAuthenticationToken token = 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";
CrmService service = new CrmService();
service.Url = "http://<servername>:<port>/mscrmservices/2007/crmservice.asmx";
service.CrmAuthenticationTokenValue = token;
service.Credentials = System.Net.CredentialCache.DefaultCredentials;

// Create a removeparent target.
TargetRemoveParentSystemUser target = new TargetRemoveParentSystemUser();

// Assign to the target the ID of the user to remove a parent from.
target.EntityId = new Guid("1DCDEE97-35BB-44BE-8353-58BC36592656");

// Create a removeparent request.
RemoveParentRequest request = new RemoveParentRequest();
request.Target = target;

// Execute the request.
[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"
Dim service As New CrmService()
service.Url = "http://<servername>:<port>/mscrmservices/2007/crmservice.asmx"
service.CrmAuthenticationTokenValue = token
service.Credentials = System.Net.CredentialCache.DefaultCredentials

' Get the ID of the current user. 
Dim whoRequest As New WhoAmIRequest()
Dim whoResponse As WhoAmIResponse = CType(service.Execute(whoRequest), WhoAmIResponse)
Dim myUserId As Guid = whoResponse.UserId
Dim myBusinessUnitId As Guid = whoResponse.BusinessUnitId

' Get the ID of system user.
Dim query As New QueryByAttribute()
query.EntityName = EntityName.systemuser.ToString()
query.Attributes = New String() { "lastname" }
query.Values = New Object() { "SYSTEM" }
' Be aware that using AllColumns may adversely affect 
' performance and cause unwanted cascading in subsequent 
' updates.  A best practice is to retrieve the least amount of 
' data required.
query.ColumnSet = New AllColumns()

' If the current user is the system user, use the INTEGRATION user.
Dim user As systemuser = CType(service.RetrieveMultiple(query).BusinessEntities(0), systemuser)
If user.systemuserid.Value = myUserId Then
   query.Values = New Object() { "INTEGRATION" }
   user = CType(service.RetrieveMultiple(query).BusinessEntities(0), systemuser)
End If

' Make me the parent of the new user.
Dim setParentRequest As New SetParentSystemUserRequest()
setParentRequest.ParentId = user.systemuserid.Value
setParentRequest.UserId = myUserId

See Also



© 2010 Microsoft Corporation. All rights reserved.