Adding a new column to multiple content types contained in a single list

Feb 5, 2015 at 8:03 PM
I have a script that is adding a column "Category" to a calendar list. I have accomplished this with SPServices (still the greatest tool to me since it's inception).

My problem is that the calendar contains multiple content types. What I need to happen is to add this column and have it added to all the content types (as can occur when you add a column through the interface and leave the "Add to all content types" and "Add to default view" boxed checked). Does this option exist in SPServices?

If not, is there a way to designate which content type I add the column to? If this is possible I could loop through and add it to each.

Please note that I am writing this script for SharePoint 2007 but I will need to make it work in 2010 in the near future.

Here is a snippet of the code to add the column:
function addNewCategoryField(){
   var fields = '<Fields>';
   fields += '<Method ID="1"><Field Type="Choice" Name="Category" DisplayName="Category">';
   fields += '<CHOICES>';
   for(i=0;i<arrayContentType.length;i++){
      fields += '<CHOICE>' + arrayContentType[i] + '</CHOICE>'; // adding choices to match Content Types
   }
   fields += '</CHOICES>';
   fields += '</Field>';
   fields += '</Method>';
   fields += '</Fields>';

   doUpdateList(fields);
}

function doUpdateList(fields){

   if(isCategoryPresent){ // elsewhere in my code this checks to see if the Category field already exists
      fieldsToUpdate = fields;
      fieldsToAdd = "";
   }
   else{
      fieldsToUpdate = "";
      fieldsToAdd = fields;
   }   
       
   $().SPServices({
      operation: "UpdateList",
      listName: curListGUID,
      listProperties:"",
      updateFields: fieldsToUpdate,
      newFields: fieldsToAdd,
      deleteFields: "",
      listVersion: "",
      async: false,
      completefunc: function (xData, Status){
         alert(xData.responseText);
         if(Status == 'success'){
            alert(status);
         }        
      }
   });
}
Apr 19, 2015 at 4:10 PM
Hi Den,

I am experiencing a similar issue. However, I would like to add a new field to a list but not add it to the default content type. Please let me know if you have figured out the solution. Might help me as well.

Thanks,
Coordinator
Apr 29, 2015 at 1:07 PM
You should be able to add a column to the list with UpdateList. (It sounds like neither of you want to add the column to any of the applied Content Types.)

If you do want to add the column to a specific Content Type, then you should probably use UpdateContentType.

M.