I have to update formula of calculated field. I wrote method for that, it is working fine and is updating formula as well. But it takes really long time to update formula in large library ie library with more than 5000 documents.
private void changeFormulaForThisField(SPField field, String newFormula)
{
if (field.Type == SPFieldType.Calculated)
{
SPFieldCalculated calcField = (SPFieldCalculated)field;
if (calcField.Formula == newFormula)
{
writeLogMessage("Column [" + field.Title + "], Old and new formula same");
}
else
{
calcField.Formula = newFormula;
if (!TESTMODE)
{
calcField.Update(true);
}
writeLogMessage("Column [" + field.Title + "], updating formula...done");
}
}
}
I checked doing same ie updating formula using SharePoint UI. It seems it also depends on number of documents in library. For small library, it is really fast. For large library, it takes also long time in UI, but not so long as using my code.
Am I doing something wrong or inefficient way in my code ? Does updating formula/title for one spfield also needs to update formula/title for each items or what ? Have you experienced such behaviour before ?
Any response would be helpful.
Thanks.