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
BoolsEyeBoolsEye 

Set custom currency field to null does not work

I tried to set a custom currency (double) field to null using the AJAX toolkit (beta 3.3) but it does not work.
 
The field is in the fieldsToNull array of the DynaBean and nillable is true but it is ignored during saving. The value stays the same.
 
Setting my value to 0 works, so saving is fine.
 
Is it not possible to set a currency field to null using the toolkit ?
 
Thanks,
 
// Juergen
DevAngelDevAngel
Hi Boolseye,

This may be a bug, I'll check and see if it is.
DevAngelDevAngel

Hi BoolsEye,

Not a bug.  Although I don't like the way it works.  What you need to do, is when you have an object that you need to set the fieldsToNull on, you can't reuse the object for update.  You need to create a new Dynabean for the object to be updated, set the fieldsToNull and set only the other fields that you need to have updated.

Code:

var sobj = sforceClient.query("Select Id, Name, some_field__c, " + "
     a_currency_field__c from Opportunity Where Id = '00630000002eRTl'");

//Create a new oppty record
var oppty = new Sforce.Dynabean("Opportunity");
//Set the fields to null
oppty.fieldsToNull = ["a_currency_field"];
//Set a new value to be updated
oppty.set("some_field__c", "The new updated value");
//Set the ID so the update will work
oppty.set("Id", sobj.get("Id"));
//Update the record, obtaining a save result
var sr = sforceClient.update([oppty])[0];
//Check the results of the operation
if (sr.success == true) {
    alert("We successfully updated the record.");
} else {
    alert("The update failed due to: " + sr.errors[0].message);
}


 

Message Edited by DevAngel on 07-25-2006 09:11 AM

BoolsEyeBoolsEye

Ok, thank you.

// Juergen

SteveBowerSteveBower
I have not found this to be the case.

I *have* found that if you take an existing Dynabean, set the fieldsToNull to include specified field and do an update, it will NOT set the field to null.

However if you ALSO set the value of the field to null, it will.

So, I use:

Code:
Sforce.Dynabean.prototype.setOrNull = function(propName, value) { 
 // If the value is null, add it to the fieldsToNull array.
 // otherwise, use the .set function to add the value to the record.
 if (value == "" || value == null ) {
  this.fieldsToNull.push(propName);
  this.set(propName,null);
 } else {
  this.set(propName,value);
 }
}

But, if I were to get rid of the line:  this.set(propName,null);  it would not work.

Personally, I don't understand why the .set() function in the Ajax toolkit doesn't just do what I've defined above.  It's so clearly what we all want and expect it to do.

Thanks, Steve Bower.