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
NashornNashorn 

AJAX fieldsToNull

I am programming with AJAX and am trying to set some fields to null on an object.

I tried this, but it didn't work:

var opportunity = queryResult.records[0]; //an opportunity pulled from the database
var aFieldsToNull = new Array(1);
aFieldsToNull[0]= "field_name__c";
opportunity.set("fieldsToNull", aFieldsToNull);

I tried this, but it also didn't work:

var aFieldsToNull = new Array(1); //an opportunity pulled from the database
aFieldsToNull[0]= "field_name__c";
var propNull = new DynaProperty("fieldsToNull",aFieldsToNull);
opportunity.addProperty(propNull);

Does anyone know how to set a field to null? The only info I have found on this message board is this hack: http://forums.sforce.com/sforce/board/message?board.id=general_development&message.id=4794

I am hoping that there is a better way to do this.

Thanks for any help!

Message Edited by Nashorn on 01-16-2006 01:05 AM

DevAngelDevAngel
Well, how about this?

var opportunity = queryResult.records[0];
opportunity.fieldsToNull.push("field_name__c");
NashornNashorn
Thanks! I just tried that and it works.

However, there is one exception. This solution doesn't work for fields that I have that are of type currency(18,0).

For instance, I have an Account, and an "Online Revenue" custom field has been set to either blank, or to 0 using the Edit Account page. My S-Control reads this field and determines that it is null. I want to set this value for an Opportunity, so I use fieldsToNull.push() to set it to null for the Opportunity.

The fieldsToNull.push() call works fine, so long as the value of a field of type currency(18,0) has not been set to 0 or to blank. In that case, my script does not update any fields at all, although it doesn't give an error in the Javascript console either.

Does anyone know how I can solve this problem?

Thanks
Big ChewyBig Chewy
I'm having a similar issue but I don't seem to have the method .push available to me. 

            login();
            SFService.sObject order = new SFService.sObject();
            order.type = "Order_and_Appointment__c";
            SFService.SaveResult[] sr = null;
            string id = "";
            XmlDocument xDoc = new XmlDocument();
            XmlElement e1 = null;
            XmlElement e2 = null;
            XmlElement e3 = null;
            XmlElement e4 = null;
            XmlElement e5 = null;

            e1 = xDoc.CreateElement("id");
            //the following gets the Salesforce.com id
            order.Id = apptID;
            e1.InnerText = apptID;
            e2 = xDoc.CreateElement("Order_Status__c");
            e2.InnerText = "Ready to Schedule";
            e3 = xDoc.CreateElement("REM_Medical_Provider__c");
            e3.InnerText = "";
            e4 = xDoc.CreateElement("RM_Made_By__c");
            e4.InnerText = "";
            //e5 = xDoc.CreateElement("Appt_Date_and_Time__c");
            //e5.InnerText = null;

            //NEED TO FIGURE OUT HOW TO SET APPT DATE TO NULL.  The line below does not work
            order.fieldsToNull.push("Appt_Date_and_Time__c");
           
            order.Any = new XmlElement[] {e2, e3, e4};
            sr = binding.update(new SFService.sObject[] { order });

I would much appreciate any help.  Been banging my head against this for a while.

Eric