Logo 
Search:

Sharepoint Forum

Ask Question   UnAnswered
Home » Forum » Sharepoint       RSS Feeds

Unable to update a the default formula of a calculated field?

  Asked By: Fredrick    Date: Nov 09    Category: Sharepoint    Views: 2374

Does anyone see anything wrong with this code (no errors it just
doesn't do the update)?

foreach (SPList List in Lists)
{
// Populate all lists with the Work Request ID and
Work Request Name

if (List.BaseTemplate.ToString() == "DocumentLibrary")
{
List.Fields["Work Request ID"].DefaultFormula
= "=\" + RequestID + \"";
List.Fields["Work Request Name"].DefaultFormula
= "=\" + RequestName + \"";
List.Update();
}

Share: 

 

2 Answers Found

 
Answer #1    Answered By: Mariel Ferrell     Answered On: Nov 09

In the MSDN notes, they offer this approach:

Visual Basic
Dim siteCollection As SPSite = SPContext.Current.Site

Dim list  As SPList =

siteCollection.AllWebs("Site_Name").Lists("List_Name")

Dim field  As SPField = list.Fields("Field_Name")

field.DefaultValue = "Default_Value"

field.Description = "Description"

field.Title = "New_Field_Title"

field.Update()
C#
SPSite oSiteCollection = SPContext.Current.Site;
SPList oList =
oSiteCollection.AllWebs["Site_Name"].Lists["List_Name"];
SPField oField = oList.Fields["Field_Name"];

oField.DefaultValue = "Default_Value";
oField.Description = "Description";
oField.Title = "New_Field_Title";

oField.Update();

Have you tried operating directly on a Field object like this? Alternately,
you might try testing your code  with a simpler value just to see if there is
a problem with the way that you are concatenating the string. Or try to loop
through and read the existing values, if there are any, just to make sure
your loop logic is correct..

 
Answer #2    Answered By: Santana Osborn     Answered On: Nov 09

You may want to check AllowUnSafeUpdates() function.

 




Tagged: