Updating Formula of a Calculated Column using UpdateList

Mar 19, 2015 at 4:19 AM
Hi, I am getting "Operation Failed" error when I try to update the formula of a calculated column. The sample code is:

$().SPServices({
operation: "UpdateList",
listName: 'Test List',
updateFields: "<Fields><Method ID='1'><Field Name='ResultVal'><Formula>=Sum(1+2)</Formula><FormulaDisplayNames>=Sum(1+2)</FormulaDisplayNames></Field></Method></Fields>"
});

Is it because Calculated Fields are ReadOnly? Any comments appreciated!
Coordinator
Mar 20, 2015 at 2:27 PM
I haven't tried this before. I wonder if there's some sort of escaping required on the formula? In theory you should be able to do this. The values of calculated columns are read-only, but the formula ought to be settable.

M.
Mar 22, 2015 at 5:36 AM
Edited Mar 22, 2015 at 5:47 AM
@Marc: Thanks for the comment.

I am not quite sure if escaping would be required. Because, if I set the newFields property to a similar string as listed above, it works:

$().SPServices({
operation: "UpdateList",
listName: 'Test List',
newFields: "<Fields><Method ID='1'><Field Type='Calculated' DisplayName='ResultVal' ResultType='Number'><Formula>=SUM(1+2)</Formula><FormulaDisplayNames>=Sum(1+2)</FormulaDisplayNames></Field></Method></Fields>"
});
Mar 22, 2015 at 5:56 PM
Found the answer to the problem. While updating a field, both the "DisplayName" and the "Name" of the field need to be specified.

$().SPServices({
operation: "UpdateList",
listName: 'Testing List',
updateFields: "<Fields><Method ID='1'><Field Type='Calculated' Name='Calculation1' DisplayName='Calculation1' ResultType='Number'><Formula>=SUM(1+9)</Formula><FormulaDisplayNames>=Sum(1+9)</FormulaDisplayNames></Field></Method></Fields>"
});
Marked as answer by hsingh58 on 3/22/2015 at 9:56 AM