CreateObjectEx Method |
Sample Code for creating a Lead using the CreateObjectEx method of CampusNexus CRM COF iService.
In the following sample code we will be creating an item of the Lead Object, which is a custom Team type of Object in CampusNexus CRM, with the following Properties details:
-
Name - John Peter
-
Campus - Lake District
-
Team - Lake District
-
E-mail – John@WorldWaves.com
-
SSN - 323-54-9867
-
Phone – 566-523-4352
-
Method of contact – Walk–In
The Method of contact Property is an enumerated Property. For this Property, you must pass the ID of the index of the enumerated value of this Property as the value. For example, the ID of the index of the Walk-In enumerated value of the Method of contact Property is 4. You must pass 4 as the value for the Method of contact Property.
For information on finding the ID of the index of an enumerated Property value, see Querying Main Database.
Additionally, we will be passing additional parameter values to ignore the mandatory check and to allow update of read-only Properties.
public void CreateLeadCofiService() { //Creating an Instance of COF iService COFWebService CofService = new COFWebService(); //Generating the Username Token Information UsernameToken userToken = getUserToken("ParkerRoy", "password"); //Associating the Username Token Information with the COF iService instance CofService.RequestSoapContext.Security.Tokens.Add(userToken); CofService.RequireMtom = false; //Initializing the input parameters long objectType = 20005; //Object type of the Lead Object string objectName = "John Peter"; // Name of the Lead item long ownerID = 1155; // ID of the User Agatha, the Owner of the Lead item long teamID = 52; // ID of the Team assigned to the Lead item. string addTeams = ""; //It is not applicable for Team Objects hence passing it as blank. //Initializing the PropertyInfo list with required Information PropertyInfo[] propertyData = new PropertyInfo[7]; // 7 properties are passed for creating a Lead item. //Setting the values of the PropertyInfo class for the Name Property of the Lead Object PropertyInfo propName = new PropertyInfo(); propName.propertyID = 4800002; ; //ID of the Name Property of the Lead Object. propName.propValue = "John Peter";//Value of the Name Property of the Lead Object. propertyData[0] = propName; //Setting the values of the PropertyInfo class for the Campus Property of the Lead Object PropertyInfo propCampus = new PropertyInfo(); propCampus.propertyID = 4810069; //ID of the Campus Property of the Lead Object. propCampus.propValue = "52"; // ID of the Lake District Team. propertyData[1] = propCampus; //Setting the values of the PropertyInfo class for the Team Property of the Lead Object PropertyInfo propTeam = new PropertyInfo(); propTeam.propertyID = 4800005; //ID of the Team Property of the Lead Object. propTeam.propValue = "52";// ID the Lake District Team. propertyData[2] = propTeam; //Setting the values of the PropertyInfo class for the E-mail Property of the Lead Object PropertyInfo propEmail = new PropertyInfo(); propEmail.propertyID = 4810065; ; //ID of the E-mail Property of the Lead Object. propEmail.propValue = "john@gmail.com";//Value of the E-mail Property of the Lead Object. propertyData[3] = propEmail; //Setting the values of the PropertyInfo class for the SSN Property of the Lead Object PropertyInfo propSSN = new PropertyInfo(); propSSN.propertyID = 4810090; //ID of the SSN Property of the Lead Object. propSSN.propValue = "323-54-9867";// Value of the SSN Property of the Lead Object. propertyData[4] = propSSN; //Setting the values of the PropertyInfo class for the Phone Property of the Lead Object PropertyInfo propPhone = new PropertyInfo(); propPhone.propertyID = 4810086; //ID of the Phone Property of the Lead Object. propPhone.propValue = "566-523-4352";//Value of the Phone Property of the Lead Object. propertyData[5] = propPhone; //Setting the values of the PropertyInfo class for the Method of contact Property of the Lead Object PropertyInfo propMethodOfContact = new PropertyInfo(); propMethodOfContact.propertyID = 4810075; //ID of the Method of contact Property of the Lead Object. propMethodOfContact.propValue = "4";// Index of the enumerated value of the Method of contact Property. propertyData[6] = propMethodOfContact; long InstanceID = -1; // Passing the instance ID as -1 as we are creating a new Object item. long result = 0; //Setting the return value as success so that correct value is reflected when method call completes. string error = ""; // Error description obtained on method completion. OperationParams operationParams = new OperationParams(); operationParams.ignoreMandatoryCheck = true; operationParams.updateReadOnlyProperties = true; result = CofService.CreateObjectEx(objectType, objectName, ownerID, teamID, addTeams, propertyData,operationParams, out InstanceID, out error); if (result != 0) { //Handle Error } }