Show or hide fields in list forms in SharePoint 2013, SharePoint Online (Office 365)


Using Visual Studio at provision time, you can set the properties in the list’s Schema.xml:
<Field Name=”SomeField” ShowInDisplayForm=”FALSE” ShowInNewForm=”FALSE” ShowInEditForm=”FALSE” ShowInViewForm=”FALSE”></Field>

Though, if you later need to update these properties for an already deployed field, you can do this using JavaScript (JSOM). Just navigate with your browser to any list in the site, open the console and run:

var ctx = SP.ClientContext.get_current(),
  field = ctx.get_web().get_lists().getByTitle('MyList').get_fields().getByInternalNameOrTitle("MyField");
field.setShowInDisplayForm(false); // false to hide, true to show
field.setShowInNewForm(false);
field.setShowInEditForm(false);
field.setShowInViewForm(false);

ctx.executeQueryAsync(function() { console.log('Field updated');},
                      function(sender, args) {
                          console.log('Eroare: ', args.get_message());
                      }
                      );