Using the JSOM in SharePoint 2010, if I am creating lists programmatically using something like:
this.myField= oList.get_fields().addFieldAsXml('<Field DisplayName=\'Key\' Type=\'Text\' />', true, SP.AddFieldOptions.defaultValue);
var fieldObj = clientContext.castTo(myField,SP.FieldNumber);
fieldObj.set_defaultValue('-');
fieldObj.update();
clientContext.load(myField);
and something list this for updating the list...
this.oList = oWebsite.get_lists().add(listCreationInfo);
oList.set_description('New Announcements List');
oList.update();
clientContext.load(oList);
but what if I want to access like the title column that already gets created and change its default value to "..." and remove it from the default view. Am I able to do that?
EDIT: this seems to be right along the lines of where I am trying to get however I can't seem to get at the ViewFields of the CAML, only the Query portion.
var listCollection = web.get_lists();
var list = listCollection.getByTitle("ExampleList");
var viewCollection = list.get_views();
var view = viewCollection.getByTitle("All Items");
var query = '<OrderBy><FieldRef Name=\'Title\' Ascending=\'False\' /></OrderBy>';
//instead of set_viewQuery I would like to get at the ViewFields...is that possible?
view.set_viewQuery(query);
view.update();
Tried this, but I can't get it to change the list's default All Items View, it seems to only remove it from the forms for me??
var cxt = new SP.ClientContext.get_current();
var oWebsite = cxt.get_web();
this.oList = oWebsite.get_lists().getByTitle('ExampleList);
fieldCollection = oList.get_fields();
this.oneField = fieldCollection.getByInternalNameOrTitle("Title");
this.oneField.set_hidden(true);
this.oneField.set_required(false);
this.oneField.update();
cxt.load(this.fieldCollection);
cxt.load(this.oneField);
cxt.executeQueryAsync(Function.createDelegate(this, this.onUpdatedTitleFieldSuccess), Function.createDelegate(this, this.onQueryFailed));
I also noticed that if I use the above, the All Items view still shows Title, but it is removed from the form, and if I browse through the web UI to list settings, the column does not appear in the columns list....weird.