任何人都可以了解以下代码为什么不更改任务状态,即使调用返回成功消息:
public bool markTaskCompleted(String id)
{
try
{
sObject UpdateTask = new sObject();
UpdateTask.type = "Task";
UpdateTask.Id = id;
System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
XmlElement afield = doc.CreateElement("Status");
XmlText txtNode = doc.CreateTextNode("Completed");
afield.AppendChild(txtNode);
SaveResult[] saveResults = binding.update(new sObject[] { UpdateTask });
if (saveResults[0].success)
return true;
else
{
for (int i = 0; i < saveResults[0].errors.Length; i++)
{
Error err = saveResults[0].errors[i];
System.Windows.Forms.MessageBox.Show("Errors were found on item 0" + Environment.NewLine +
"Error code: " + err.statusCode.ToString() + Environment.NewLine +
"Error message: " + err.message);
}
return false;
}
}
catch (System.Web.Services.Protocols.SoapException e)
{
System.Windows.Forms.MessageBox.Show("An unexpected error has occurred: " + e.Message + " Stack trace: " + e.StackTrace);
return false;
}
}
答案 0 :(得分:0)
自己找到它。我错过了以下关键路线:
UpdateTask.Any = new System.Xml.XmlElement[] { afield };
此行应在afield.AppendChild(txtNode);
行后立即添加。现在它正在更新状态。