function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
ABShellABShell 

possible sforceClient.Update() bug

During an update, a property that was set to null or empty is not getting updated.

//this line will not update the Approver__c attribute if the value is null
oppt.set("Approver__c", products[pos].get("Approver__C"));

Please advise.
DevAngelDevAngel
Hi ABShell,

Well, it seems that the fieldsToNull property is missing from the Dynabean implementation. I will post a new version with fieldsToNull support and post a workaround as well.
DevAngelDevAngel
Here is the code for the workaround. You can dynamically add the fieldsToNull array to the object. When the page or control is intialized, you need to override the toSObject function with the one shown below. For the fix, the Dynabean object will have a new array property called fieldsToNull and the toSObject function will be replaced with the one below. This fix should be available in the published beta2 and beta1 toolkits by Wed Nov 2, 2005. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <title></title> <meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1"> <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5"> <script src="https://www.sforce.com/ajax/beta2/sforceclient.js" type="text/javascript"></script> <script language=javascript> <!-- function initPage() { sforceClient.init("{!API_Session_ID}", "{!API_Partner_Server_URL_60}"); sforceClient.Login("username", "password"); DynaBean.prototype.toSObject = function beanToSObject(filter) { var output = "<sObjects xmlns:ns3=\"urn:sobject.partner.soap.sforce.com\">"; output += "<type xmlns=\"urn:sobject.partner.soap.sforce.com\">" + this.getName() + "</type>"; for (var i = 0;i<this.fieldsToNull.length;i++) { output += "<fieldsToNull>" + this.fieldsToNull[i] + "</fieldsToNull>"; } for (key in this.getProperties()) { var prop = this.getProperties()[key]; if (dltypeof(prop) == "Property") { var fldDef = this.getDefinition().fieldMap[prop.getName().toLowerCase()]; if (fldDef != null) { var addField = true; if (filter != undefined) { if (filter == "forupdate") { addField = (fldDef.updateable == true || fldDef.name.toLowerCase() == "id"); } else if (filter == "forcreate") { addField = (fldDef.createable == true); } } if (addField == true) { prop.type = fldDef.type; output += prop.toSoap(); } } } } output += "</sObjects>"; this.setSoap(output); return output; }; var qr = sforceClient.Query("Select Id From Lead Where Id = '00Q30000005qYJQEA2'"); var lead = qr.records[0]; lead.fieldsToNull = new Array(); lead.fieldsToNull.push("Industry"); lead.fieldsToNull.push("LeadSource"); var sr = sforceClient.Update([lead])[0]; if (sr.success == true) { alert("Update was successful..."); } else { alert("Update failed: " + sr.errors[0].message); } } //--> </script> </head> <body onload= "initPage()"> </body> </html>

Message Edited by DevAngel on 10-28-2005 10:01 AM

Chris DChris D
Hi Dave,
Have you published the fix? If so, where can I grab it?

Thanks,
Chris David

Edit: Sorry for my confusion, this message board posts threaded replies in reverse chronological order and I didn't see your workaround. Where can I obtain the latest build of Beta 2 with this fix already included?

Message Edited by Chris D on 11-22-2005 02:22 PM

DevAngelDevAngel
You can find this at https://www.sforce.com/ajax/beta2/sforceclient.js