nitadmin
asked on
CRM 3.o SDK and creating a Contact object.
Hi,
I have written this piece of code using C# and Visual Studio 2005.
I want to be able to create a contact object for every Account object that I create for Microsoft CRM 3.0
My C# code is listed below.
With this code, CRM web Service will throw an Exception.
if I were to comment out these two lines from the code.
objContact.parentcustomeri d = new Customer();
objContact.parentcustomeri d.Value = new Guid(custID);
the code will execute without throwing any exceptions, but then the contact which gets created does not have its Parent Account set. What I want to do is have a Contact object created for every Account I create.
How do I correct these two lines of code so that no exceptions are thown and Contacts gets it Parent Account assigned.
CrmService service = new CrmService();
service.Credentials = System.Net.CredentialCache .DefaultCr edentials;
service.Timeout = 3000 * 10000;
service.PreAuthenticate = false;
// Create the account object.
contact objContact = new contact();
// Set the properties of the account object.
objContact.firstname = fname;
objContact.lastname = lname;
objContact.emailaddress1 = eaddress;
// Assign Parent CustomerId for contact.
objContact.parentcustomeri d = new Customer();
objContact.parentcustomeri d.Value = new Guid(custID);
String ListId = getContactID(fname, lname);
if ((ListId.CompareTo("empty" )) != 0)
{
// contact already exist
return;
}
else
{
// does not exist. So will add a new contact object
}
// Create the target object for the request.
TargetCreateContact target = new TargetCreateContact();
// Set the properties of the target object.
target.Contact = objContact;
// Create the request object.
CreateRequest create = new CreateRequest();
// Set the properties of the request object.
create.Target = target;
// Execute the request.
CreateResponse created = (CreateResponse)service.Ex ecute(crea te);
I have written this piece of code using C# and Visual Studio 2005.
I want to be able to create a contact object for every Account object that I create for Microsoft CRM 3.0
My C# code is listed below.
With this code, CRM web Service will throw an Exception.
if I were to comment out these two lines from the code.
objContact.parentcustomeri
objContact.parentcustomeri
the code will execute without throwing any exceptions, but then the contact which gets created does not have its Parent Account set. What I want to do is have a Contact object created for every Account I create.
How do I correct these two lines of code so that no exceptions are thown and Contacts gets it Parent Account assigned.
CrmService service = new CrmService();
service.Credentials = System.Net.CredentialCache
service.Timeout = 3000 * 10000;
service.PreAuthenticate = false;
// Create the account object.
contact objContact = new contact();
// Set the properties of the account object.
objContact.firstname = fname;
objContact.lastname = lname;
objContact.emailaddress1 = eaddress;
// Assign Parent CustomerId for contact.
objContact.parentcustomeri
objContact.parentcustomeri
String ListId = getContactID(fname, lname);
if ((ListId.CompareTo("empty"
{
// contact already exist
return;
}
else
{
// does not exist. So will add a new contact object
}
// Create the target object for the request.
TargetCreateContact target = new TargetCreateContact();
// Set the properties of the target object.
target.Contact = objContact;
// Create the request object.
CreateRequest create = new CreateRequest();
// Set the properties of the request object.
create.Target = target;
// Execute the request.
CreateResponse created = (CreateResponse)service.Ex
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
objContact.parentcustomeri
thanks.