Adding nested entities using SOAP API

SOLVED

Can anyone tell me how to add (eg.) a new person to a company record using the SOAP API.

I can create the person with an add("person", ...}) call, but I can't see how to then add them to a company.people collection - calling update("company",...) doesn't do it.

Thanks!

Parents
  • 0

    I'm still stuck with this - can anyone help?  I'm trying to add a new nested entity (eg. person, phone, email, address) to an existing company

  • 0 in reply to Geoff Turner

    Geoff

    Have you seen this article?  https://www.sagecity.com/sage-global-solutions/sage-crm/b/sage-crm-hints-tips-and-tricks/posts/sage-crm-2018-r1-a-round-up-of-articles-about-using-soap-web-services

    That has a link to this article  https://www.sagecity.com/sage-global-solutions/sage-crm/b/sage-crm-hints-tips-and-tricks/posts/adding-a-company-entity-using-the-sage-crm-soap-web-service-api

    This has some to show how to add a new company with the sub records.  If you want to add a person to a company then it also has examples of how to add child records to an existing entity.

  • 0 in reply to Sage CRM

    Thanks - I hadn't found the "roundup" article.  This article solved how to add a new address or person, as the address/person can have CompanyIDSpecified (I should have noticed that!).  But I'm still left with a problem adding emails and phones, as they don't have a CompanyID field (as they can link to companies or people etc).  I guess it's something to do with their intid / intforeignid fields, so will experiment.

  • +1 in reply to Geoff Turner
    verified answer

    This is an example of how to add an email


    private void buttonAdditionalEmail_Click(object sender, EventArgs e)
    {
    try
    {
    ewarebase[] CRMBase = new ewarebase[1];
    email extraEmail = new email();
    extraEmail.emailaddress = "[email protected]";
    extraEmail.type = "Sales";
    CRMBase[0] = extraEmail;
    addresult CRMaddResult = CRMService.add("email", CRMBase);
    crmid myID = (crmid)CRMaddResult.records[0];
    //Assumes EmailLink has been exposed to web services but uses addrecord because the local wsdl has not been updated. 
    crmrecord[] myEmailLinkSet = new crmrecord[1];
    crmrecord myEmailLinkRecord = new crmrecord();
    myEmailLinkRecord.entityname = "emaillink";
    myEmailLinkRecord.records = new recordfield[4];
    recordfield aEntityID = new recordfield();
    aEntityID.name = "entityid";
    aEntityID.value = "5";
    aEntityID.type = crmrecordtype.integer;
    aEntityID.typeSpecified = true;
    recordfield aRecordID = new recordfield();
    aRecordID.name = "recordid";
    aRecordID.value = textboxComp_Companyid.Text;
    aRecordID.type = crmrecordtype.integer;
    aRecordID.typeSpecified = true;
    recordfield aType = new recordfield();
    aType.name = "type";
    aType.value = "Sales";
    aType.type = crmrecordtype.@string;
    aType.typeSpecified = true;
    recordfield aEmailID = new recordfield();
    aEmailID.name = "emailid";
    aEmailID.value = myID.crmid1.ToString();
    aEmailID.type = crmrecordtype.integer;
    aEmailID.typeSpecified = true;
    myEmailLinkRecord.records[0] = aEntityID;
    myEmailLinkRecord.records[1] = aRecordID;
    myEmailLinkRecord.records[2] = aType;
    myEmailLinkRecord.records[3] = aEmailID;
    myEmailLinkSet[0] = myEmailLinkRecord;
    addresult aResult = CRMService.addrecord("emaillink", myEmailLinkSet);
    //ewarebase[] CRMBase = new ewarebase[1];
    //CRMCompany.companyid = int.Parse(textboxComp_Companyid.Text);
    //CRMCompany.companyidSpecified = true;
    //CRMCompany.email = new ewarebaselist();
    //CRMCompany.email.records = new ewarebase[1];
    //CRMCompany.email.entityname = "email";
    //email extraEmail = new email();
    //extraEmail.emailaddress = "[email protected]";
    //extraEmail.type = "Sales";
    //CRMCompany.email.records[0] = extraEmail;
    //CRMBase[0] = CRMCompany;
    ////addresult CRMaddResult = CRMService.add("company", CRMBase);
    //addresult CRMaddResult = CRMService.add("company", CRMBase);
    }
    catch (Exception MyError)
    {
    MessageBox.Show(MyError.Message);
    }
    }
  • 0 in reply to Sage CRM

    Thanks again - the key bit is "Assumes EmailLink has been exposed to web services".  Which it wasn't, and why I was finding it so difficult!

Reply Children
No Data