1

I need to add dissappeared ViewField to my List view (Calendar). it was before, but was dropped after I switched default view to another, and then returned back (I swutched my view back to 'Default View', but now it does not contain needed field)

I see something here on stackoverflow post, but not sure it is JSOM. Can I use JSOM to do something same? There is too little documentaion about it..

Maybe somebody did the same before. Something like this:

    var web = clientContext.get_web();

    var listCollection = web.get_lists();
    var list = listCollection.getByTitle("Rooms");
    var viewCollection = list.get_views();

    // CSOM here..
    SPView view = list.DefaultView;
    view.ViewFields.Add("My_Room_Name");
    view.Update();
    // ..

    clientContext.executeQueryAsync(function () {

    }, onFail);
1

Almost there, instead of adding fields individually, you can add it as a collection.

Modify it from below sample:

var viewCollection = list.get_views();
var view = list.get_defaultView();

var viewFields = ["Title","Description","My_Room_Name"];  
view.set_viewFields(viewFields);  
view.Update();

context.load(view);
context.executeQueryAsync(function(){
        console.log("sucess changing viewFields");
    },  
    function(sender,args){  
        console.log(args.get_message());  
});  

Reference - SP.ViewCreationInformation.viewFields property

0

Great that this field is not readonly. Thanks much Gautam, I haven't used collection but this worked for me:

function addViewField() {

    var clientContext = new SP.ClientContext.get_current();
    var web = clientContext.get_web();
    var listCollection = web.get_lists();
    var list = listCollection.getByTitle("Rooms List");

    var defaultView = list.get_defaultView();
    var defaultViewFields = defaultView.get_viewFields();

    defaultViewFields.add("Conference_Room");

    defaultView.update();
    clientContext.executeQueryAsync(function () {
        console.log("ViewField added");
    }, onFail);
}

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.