0

I have created a SharePoint feature where I have added a list named "Employees".

I have added a Content Type "Employee" and added to it some columns like "Vacation Days Taken", "Vacation Days Earned"... I added also a calculated column "Vacation Days Left" which is the difference between the first two columns.

In the Feature Activated event receiver I have created a view where I added all the "Employee" content type columns.

SPViewCollection allviews = employees.Views;
string viewName = "Employees View";
System.Collections.Specialized.StringCollection viewFields = new System.Collections.Specialized.StringCollection();
viewFields.Add("Employee");
viewFields.Add("Vacation Days Earned");
viewFields.Add("Vacation Days Taken");
viewFields.Add("Vacation Days Left");
viewFields.Add("Startup Date");                 
allviews.Add(viewName, viewFields, null, 100, true, true);

I am getting the following error:

Column 'Vacation Days Left' does not exist. It may have been deleted by another user.

Notes:

web.Fields["Vacation Days Left"] => Not Null
employees.Fields["Vacation Days Left"] => Null  
employees.ContentTypes["Employee"].Fields["Vacation Days Left"] => Not Null

I can add the calculated field after deployment to the view manually.

1

I found the error. I was creating the calculated field like this:

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">  
  <Field
       ID="{dce31cdd-926a-468d-b921-68a921419215}"
       Name="VacationDaysLeft"
       DisplayName="Vacation Days Left"
       Type="Calculated"
       Required="FALSE"        
       Group="Intranet Columns">
    <Formula>=[Vacation Days Earned]-[Vacation Days Taken]</Formula>
  </Field>
</Elements>

So I was missing the ResultType attribute. I should have added:

ResultType="Number"
0

Are you updating your "employees" list after adding your columns by code? Because if you don't, the columns will be added to the site and function normally but will not be added to your list view!

  • I am creating the columns in an Elements.xml file. The calculated field is giving me errors, if I remove it the view will be created successfully. – user3470 Jun 11 '13 at 6:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy