Updating leads via web services

I'm trying to update some records via web services. I have some input data which consists of a list of email addresses in a spreadsheet. I need to go through that list 1 by 1 and for each email address return all the matching leads. Once I have my list of leads, which will either be 0, 1 or more than 1, I need to update each record returned by setting 2 checkboxes on the record.


Reading the list of email addresses in from the spreadsheet is simple enough and I have done that. I then call a function that processes the leads. It takes 3 parameters which are the email address, field one and field two. Fields one and two are checkbox values so Y or null.

Here is the function:

public int ProcessLeads(string psEmailAddress, string psFieldOne, string psFieldTwo)
{
string sWhereClause = "lead_personemail = N'" + psEmailAddress + "'";
queryresult oLeads = crm.query(sWhereClause, "lead");
ewarebase[] CRMBase = oLeads.records;
updateresult oCRMLeadUpdateResult;

for (int i = 0; i
{
lead CRMLead = (lead)CRMBase[i];

CRMLead.fieldone = psFieldOne;
CRMLead.fieldtwo = psFieldTwo;
oCRMLeadUpdateResult = crm.updaterecord("lead", CRMBase[i]);
}

return 0;
}

Ignoring the return value at the moment, I am getting a compile error on this line:

oCRMLeadUpdateResult = crm.updaterecord("lead", CRMBase[i]);

The error is:

The best overloaded method match for 'LeadManager.SageCRM.WebService.updaterecord(string, LeadManager.SageCRM.ewarebase[])' has some invalid arguments

Any ideas? All I'm looking to do is update 2 fields based on the values set in the external application.

Thanks.

  • 0

    Hi,

    You can try the following function and check whether it is working or not.

    public int ProcessLeads(string psEmailAddress, string psFieldOne, string psFieldTwo)

    {
    string sWhereClause = "lead_personemail = N'" + psEmailAddress + "'";
    queryresult oLeads = crm.query(sWhereClause, "lead");
    ewarebase[] CRMBase = oLeads.records;
    updateresult oCRMLeadUpdateResult;

    for (int i = 0; i
    {
    lead CRMLead = (lead)CRMBase[i];

    CRMLead.fieldone = psFieldOne;
    CRMLead.fieldtwo = psFieldTwo;
    CRMBase[i]=CRMLead;
    oCRMLeadUpdateResult = crm.update("lead", CRMBase);
    }

    return 0;
    }

    Hope this helps!

    Regards,
    Dinesh

  • 0

    Lee

    Do you have access to this

    community.sagecrm.com/.../27223.aspx

    It is a sample project that contains lots of examples on how to update/add/delete using SOAP web services.

    In the example below

    ewarebase[] CRMBase;

    updateresult CRMUpdateResult;

    CRMBase = new ewarebase[1];

    CRMCompany.companyid = int.Parse(textboxComp_Companyid.Text);

    CRMCompany.companyidSpecified = true;

    CRMCompany.name = textBoxComp_Name.Text;

    CRMCompany.website = textBoxComp_WebSite.Text;

    //Assumes that Dropdown fields are configured as strings in WSDL file:

    CRMCompany.source = comboBox1.Text;

    CRMBase[0] = CRMCompany;

    CRMUpdateResult = CRMService.update("company", CRMBase);

    You can see you need to specifiy the ID of the record you need to update.

  • 0

    Hi Dinesh,

    After a bit of messing around, I got that exact code! It does compile but it doesn't run properly because I need to pass in the lead id which I know how to do. I will play around with it some more today and see what I can do but thanks for the help.

    When I get it running, I'll post the function code.

    Thanks.

    Lee

  • 0

    It should load happily. You may get a few errors about solution folders but they can be ignored. The project started of life about a thousand years ago and has just been loaded and updated each time I get access to a new version of VS.

  • 0

    Thanks Jeff. I do have access. I only have Visual Studio 2010. I'll see if I can get it loaded into 2010

  • 0

    I finally managed to get it up and running. Thanks for the help!