Wednesday, October 24, 2007

Create CustomerOpportunityRole Record

This is a very simple code, when you wants to create a CustomerOpportunityRole.


try
{

// Create the class
customeropportunityrole oppRole = new customeropportunityrole();

// Define the "Customer" to relate the Opportunity to. // This could be an Account or a Contact//
oppRole.customerid = new Customer();
oppRole.customerid.Value = new Guid("605291D0-C91E-DC11-944B-0003FF0E1518");
oppRole.customerid.type = EntityName.account.ToString();

// Define what Opportunity this relationship is for
oppRole.opportunityid = new Lookup();
oppRole.opportunityid.Value = new Guid("701C12F1-896A-DC11-961B-0003FF0E1518");
oppRole.opportunityid.type = EntityName.opportunity.ToString();

// Define what Relationship Role to use
oppRole.opportunityroleid = new Lookup
oppRole.opportunityroleid.Value = new Guid("D2A640E1-B81A-DC11-A7F0-000C29C33583");
oppRole.opportunityroleid.name="Referral";
oppRole.opportunityroleid.type = EntityName.relationshiprole.ToString();

// Assign StatusCode, StateCode
CrmNumber codeNumber = new CrmNumber();
codeNumber.Value= 1;
oppRole.opportunitystatuscode = codeNumber;

codeNumber.Value= 0;
oppRole.opportunitystatecode = codeNumber;

// Create the relationship
Guid id = service.Create(oppRole);
}
catch(System.Web.Services.Protocols.SoapException ex)
{
MessageBox.Show(ex.Detail.InnerText.ToString() + ex.Message.ToString());
}

No comments: