Hi,

We can add components to the solution programmatically by passing

  •  Component meta data id
  • component type
  • Solution unique name

to “AddSolutionComponentRequest“.

Lets say, I have a solution named “Rajeev” in my organization.

My Solution
My Solution

Below is the code to add a component (i.e.,. Account entity) using IOrganization service

            this.credentials = new ClientCredentials();

this.credentials.Windows.ClientCredential = CredentialCache.DefaultNetworkCredentials;

this.organizationUri = new Uri(“http://servername/orgname/XRMServices/2011/Organization.svc”);

using (

this.serviceProxy =

new OrganizationServiceProxy(this.organizationUri, this.homeRealmUri, this.credentials, null))

{

this.serviceProxy.ServiceConfiguration.CurrentServiceEndpoint.Behaviors.Add(new ProxyTypesBehavior());

this.service = this.serviceProxy;

}

// Get component (i.e., Account) metadata

RetrieveEntityRequest retrieveForAddAccountRequest = new RetrieveEntityRequest()

{

LogicalName = Account.EntityLogicalName

};

RetrieveEntityResponse retrieveForAddAccountResponse = (RetrieveEntityResponse)this.service.Execute(retrieveForAddAccountRequest);

// Pass ‘Component Type’ (i.e., 1 for Entity)

// Account metadata Id

// Solution unique name

// To “AddSolutionComponentRequest”

AddSolutionComponentRequest addReq = new AddSolutionComponentRequest()

{

ComponentType = 1,

ComponentId = (Guid)retrieveForAddAccountResponse.EntityMetadata.MetadataId,

SolutionUniqueName = “Rajeev”

};

this.service.Execute(addReq);

🙂

Advertisements
Advertisements

Leave a comment