Add an Additional Address to an Existing Company and Person using SOAP Web Services

1 minute read time.

Below is some simple C# code that shows how to add a new Address to an existing company. The address is inserted and linked to the company and the default contact for that company.

Notes:

  • The webservice object is called CRMbinding.
  • The Company ID is assumed to be passed from a textBox control (textBoxSearch.Text) in a windows form.
  • The Company entity is retrieved to obtain to primary person ID.
  • The add() method for the Address will only create a single entry in the Address_Link table, therefore if the address is required to be associated with both the company and the person two records must be added.


private void buttonAddExtraAddress_Click(object sender, EventArgs e)
{
try
{
int intCompanyID = int.Parse(textBoxSearch.Text);
string strSQLWhereClause = "comp_companyid = '" + intCompanyID + "'";
queryentityresult CRMEntityResult = CRMbinding.queryentity(intCompanyID, "Company");
ewarebase CRMBase = CRMEntityResult.records;
//CRMCompany defined at Form level;
CRMCompany = (company)CRMBase;
 
address extraCompanyAddress = new address();
extraCompanyAddress.address1 = "AddressData1";
extraCompanyAddress.address2 = "AddressData2";
extraCompanyAddress.address3 = "AddressData3";
extraCompanyAddress.address4 = "AddressData4";
extraCompanyAddress.address5 = "AddressData5";
extraCompanyAddress.city = "London";
extraCompanyAddress.country = "UK";
extraCompanyAddress.postcode = "SW1 4LL";
extraCompanyAddress.companyid = intCompanyID;
extraCompanyAddress.companyidSpecified = true;
 
//Create a Copy of the Address for use with the Person
//A second copy needs to be entered as only one AddressLink record is created at a time.
address extraPersonAddress = new address();
extraPersonAddress.address1 = extraCompanyAddress.address1;
extraPersonAddress.address2 = extraCompanyAddress.address2;
extraPersonAddress.address3 = extraCompanyAddress.address3;
extraPersonAddress.address4 = extraCompanyAddress.address4;
extraPersonAddress.address5 = extraCompanyAddress.address5;
extraPersonAddress.city = extraCompanyAddress.city;
extraPersonAddress.country = extraCompanyAddress.country;
extraPersonAddress.postcode = extraCompanyAddress.postcode;
extraPersonAddress.companyid = extraCompanyAddress.companyid;
extraPersonAddress.companyidSpecified = extraCompanyAddress.companyidSpecified;
//These lines have the Address added to the person               
extraPersonAddress.personid = CRMCompany.primarypersonid;
extraPersonAddress.personidSpecified = true;
 
ewarebase[] CRMAddressBase = new ewarebase[2];
 
CRMAddressBase[0] = extraCompanyAddress;
CRMAddressBase[1] = extraPersonAddress;
addresult CRMAddResult = CRMbinding.add("address", CRMAddressBase);
 
MessageBox.Show(CRMAddResult.records.Length.ToString()+" Addresses Added");
}
catch (Exception MyError)
{
MessageBox.Show(MyError.Message);
}
}

  • Howdy,

    This appears to be related to the schema normalisation update in v7.1. It looks like Custom_Tables.bord_WebServiceTable is set to null by default for PhoneLink and EmailLink. This is a bug, but it's an easy one to resolve. Try setting them to Y, then use something like the following to add a new Phone record:

    private void buttonAddExtraPhone_Click(object sender, EventArgs e)

    {

    int intCompanyID = int.Parse(textBoxSearch.Text);

    string strSQLWhereClause = "comp_companyid = '" + intCompanyID + "'";

    queryentityresult CRMEntityResult = CRMbinding.queryentity(intCompanyID, "Company");

    ewarebase CRMBase = CRMEntityResult.records;

    CRMCompany = (company)CRMBase;

    phone extraCompanyPhone = new phone();

    extraCompanyPhone.areacode = "01";

    extraCompanyPhone.countrycode = "353";

    extraCompanyPhone.number = "1234567";

    extraCompanyPhone.phoneidSpecified = true;

    ewarebase[] CRMPhoneBase = new ewarebase[1];

    CRMPhoneBase[0] = extraCompanyPhone;

    addresult CRMAddResult = CRMbinding.add("phone", CRMPhoneBase);

    crmid newRecID = new crmid();

    newRecID = (crmid)CRMAddResult.records[0];

    phonelink newPhoneCompanyLink = new phonelink();

    // 5 for company, 13 for person. Found on Custom_Tables.Bord_TableId

    newPhoneCompanyLink.entityid = 5;

    newPhoneCompanyLink.recordid = intCompanyID;

    newPhoneCompanyLink.phoneid = newRecID.crmid1;

    newPhoneCompanyLink.type = "Business";

    newPhoneCompanyLink.entityidSpecified = true;

    newPhoneCompanyLink.phoneidSpecified = true;

    newPhoneCompanyLink.recordidSpecified = true;

    newPhoneCompanyLink.linkidSpecified = true;

    ewarebase[] CRMPhoneBase2 = new ewarebase[1];

    CRMPhoneBase2[0] = newPhoneCompanyLink;

    addresult CRMAddResult2 = CRMbinding.add("phonelink", CRMPhoneBase2);

    }

  • Is there a similar way of adding a phone or email to an existing company? The companyid and personid don't appear to be available within the phone or email record within Web Services.