InitializeFrom Message (CrmService)

banner art

[Applies to: Microsoft Dynamics CRM 4.0]

Find the latest SDK documentation: CRM 2015 SDK

Works for all deployment types Works online and offline

Initializes a new entity instance from an existing entity instance.

The relevant classes are specified in the following table.

Type Class
Request InitializeFromRequest
Response InitializeFromResponse
Entity account

activitypointer

businessunit

campaign

contact

contract

contracttemplate

lead

product

Remarks

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

To create the entity, pass the result to the Create method. For a list of required privileges, see InitializeFrom Privileges.

Example

The following code example demonstrates how to use the InitializeFrom message.

[C#]
// 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 the request object.
InitializeFromRequest initialize = new InitializeFromRequest();

// Set the properties of the request object.
initialize.TargetEntityName = EntityName.account.ToString();

// Create the EntityMoniker.
initialize.EntityMoniker = new Moniker();

// Set Id to the ID of the account being initialized from.
initialize.EntityMoniker.Id = created.id;

// Set the Name to the EntityType, with the first letter of each word capitalized.
initialize.EntityMoniker.Name = EntityName.account.ToString();//"Account";

// Execute the request.
InitializeFromResponse initialized = (InitializeFromResponse) service.Execute(initialize);

[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

' Create the request object.
Dim initialize As New InitializeFromRequest()

' Set the properties of the request object.
initialize.TargetEntityName = EntityName.account.ToString()

' Create the EntityMoniker.
initialize.EntityMoniker = New Moniker()

' Set Id to the ID of the account being initialized from.
initialize.EntityMoniker.Id = created.id

' Set the Name to the EntityType, with the first letter of each word capitalized.
initialize.EntityMoniker.Name = EntityName.account.ToString() '"Account";

'Execute the request.
Dim initialized As InitializeFromResponse = CType(service.Execute(initialize), InitializeFromResponse)

See Also

Reference

© 2010 Microsoft Corporation. All rights reserved.