UpdateRecord Example using the SOAP Web Services

1 minute read time.

Below is some code that shows how the UpdateRecord() method can be invoked using the SOAP Web Services. I have discussed the use of the Update() method in the article "Updating Multiselect fields using the Web Service Interface" and it is import to realise the Update() and UpdateRecord() methods are just as different as the Add() and AddRecord() methods.

The code will update a Case (case_caseid = 22) and set the description field to 'Test'.

[code language=c#]
ewarebase[] CRMBase;
crmrecord[] CaseList = new crmrecord[1];
crmrecord myCase = new crmrecord();
myCase.entityname = "Case";
myCase.records = new recordfield[2];
myCase.records[0] = Getrecordfield("caseid", "22", "integer");
myCase.records[1] = Getrecordfield("description", "Test", "string");
CaseList[0] = myCase;

CRMBase = CaseList;
updateresult CRMUpdateRecordResult = CRMService.updaterecord("Case", CRMBase);
[/code]

This code makes use of a function 'Getrecordfield' below.

[code language=c#]
private static recordfield Getrecordfield(string name, string avalue, string type)
{
recordfield aField = new recordfield();
aField.name = name;
aField.value = avalue;
switch (type)
{
case "string": aField.type = crmrecordtype.@string;
break;
case "datetime": aField.type = crmrecordtype.datetime;
break;
case "integer": aField.type = crmrecordtype.integer;
break;
case "decimal": aField.type = crmrecordtype.@decimal;
break;
case "crmrecord": aField.type = crmrecordtype.crmrecord;
break;
case "multiselectfield": aField.type = crmrecordtype.multiselectfield;
break;
}
aField.typeSpecified = true;
return aField;
}
[/code]

Not every one writes in C# so the actual XML that is passed can be seen here:

[code language=xml]




68306995826605




Case

Case

caseid
integer
22


description
string
Test





[/code]

I hope this is useful.