Quantcast
Channel: jsom – CHUVASH.eu
Viewing all articles
Browse latest Browse all 8

JSOM: Alter a column’s ShowInDisplayForm property

$
0
0

When you create a content type, you can define if your fields will be shown in DisplayForm, EditForm, NewForm. You can hide or show them, just as Yaroslav Pentsarsky says. If your list is already provisioned, you can change them with Server Object Model, why not in PowerShell: Technet: Setting ShowInDisplayForm, ShowInEditForm, ShowInNewForm properties with powershell.

If you don’t have access to the server, then the same can be done with JSOM. Here is the code:

var ctx = SP.ClientContext.get_current(),              //SP.ClientContext
    field = ctx.get_web()                              //SP.Web
               .get_lists()                            //SP.ListCollection
               .getByTitle('MyList')                   //SP.List
	       .get_fields()                           //SP.FieldCollection
	       .getByInternalNameOrTitle("Site");      //SP.Field
ctx.load(field, "SchemaXml");                          //load only SchemaXml
ctx.executeQueryAsync(function() {
	var s = field.get_schemaXml(),
	    s1 = s.replace('ShowInDisplayForm="FALSE"', 
                           'ShowInDisplayForm="TRUE"');
	field.set_schemaXml(s1);
	field.update();
	ctx.executeQueryAsync();
});

Next: JSOM: Alter a column’s DisplayName.



Viewing all articles
Browse latest Browse all 8

Trending Articles