CHUVASH.eu

CHunky Universe of Vigourous Astonishing SHarepoint :)

JSOM: Alter a column’s ShowInDisplayForm property

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.

Advertisements

7 responses to “JSOM: Alter a column’s ShowInDisplayForm property

  1. Naveen 2013-05-28 at 09:55

    Hi,
    Please find the below code
    var ctx = SP.ClientContext.get_current(),
    field = ctx.get_site()
    .get_rootWeb()
    .get_fields()
    .getByInternalNameOrTitle(“Product Type”);
    ctx.load(field, “SchemaXml”);
    ctx.executeQueryAsync(function () {
    var s = field.get_schemaXml();

    $(‘#resultpanel’).append(‘****************************** original: ‘ + s);

    s1 = s.replace(‘00000000-0000-0000-0000-000000000000’,
    ‘{655ba3db-79a3-4982-a295-54b4a4e51924}’);

    s2 = s1.replace(‘00000000-0000-0000-0000-000000000000’,
    ‘{070aef21-9b04-4f49-3595-9ffca54ef999}’);

    $(‘#resultpanel’).append(‘****************************** updating with: ‘ + s2);

    field.set_schemaXml(s2);
    field.update();
    ctx.executeQueryAsync(Function.createDelegate(this, function () {
    $(‘#resultpanel’).append(‘****************************** after Update from get_schemaXml: ‘ + field.get_schemaXml());
    }),
    Function.createDelegate(this, function (sender, args) {

    $(‘#resultpanel’).append(‘ Error – from OnLoadSuccess: ‘ + args.get_message());

    }));
    });

    I am not finding any change in the field after i run this code. You see any mistake in my code.

    In the success delegate, from field.get_schemaXml() i can see the updated schema. But still its not getting reflected on the field.

    Any help is appreciated…

    • Anatoly Mironov 2013-05-28 at 10:14

      What do you try to do? Why is the guid empty first? Have you tried some other change, like ShowInDisplayForm (from my example)? Just to verify that everything else works.

      • Naveen 2013-05-28 at 14:00

        Hey,

        Thanks for quick reply. When I pasted my code here this editor is actually hiding some xml markup. Anyhow I am trying to update the SspId, TermSetId property values for the field. I was able to change all the attribute values of the SP.field that is anything from below

        but could not change anything inside

        I am trying to use set_schemaXml method

      • Anatoly Mironov 2013-05-31 at 09:27

        Allright, if you can update all other properties, but not SspId, TermSetId, then it is something else that prevent updating it. I have not tried to update those properties with set_schemaXml. Maybe in the future, I’ll find time to investigate why it is so. If you find something, please leave a comment here.

  2. StackAndChill 2013-08-14 at 22:22

    I can’t get this working in my Office365 dev environment. Is it possible to set the XML schema in office 365?

    • Anatoly Mironov 2013-08-15 at 09:35

      Hi, it should work in Office 365, too. I haven’t tried it out, though. When you try to do in, check the response you get from the ajax call. You can see it in the Developer tools of your browser. Often you’ll get a good error message there.

  3. Egidio Caleiro Santoro 2016-04-01 at 02:15

    I’ve made a mistake in my provisiong scripts and all of my custom get_web().get_fields() are with incorrect WebId values, so are all of my custom content types that contain them. I’ve already updated the Fields in my web FieldCollection, but my ContentTypes remains incorrect. Problem is that get_web().get_contentTypes() just exposes a setter for schemaXmlWithResourceTokens method. Any idea on how can replace Contettype SchemaXml? Thank u in advance!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Вула Чăвашла

VulaCV - Чăвашла вулаттаракан сайт

Discovering SharePoint

And going crazy doing it

Bram de Jager talking Office 365, SharePoint and Azure

My view and thoughts on Productivity and more.

My programming life

and everything in between

SharePoint Development Lab by @avishnyakov

It is a good place to share some SharePoint stories and development practices.

SharePoint Dragons

Nikander & Margriet on SharePoint

Paul J. Swider - RealActivity

RealActivity is a specialized healthcare services and solution advisory firm.

Mai Omar Desouki - Avid SharePointer

Egyptian & Vodafoner - Senior SharePoint Consultant

Cameron Dwyer | Office 365, SharePoint, Outlook, OnePlace Solutions

Office 365, SharePoint, OnePlace Solutions & Life's Other Little Wonders

paul.tavares

Me and My doings!

Share SharePoint Points!!

By Mohit Vashishtha

Jimmy Janlén "Den Scrummande Konsulten"

Erfarenheter, synpunkter och raljerande om Scrum från Jimmy Janlén

Aryan Nava

BigData and Blockchain expert in Toronto

SPJoel

SharePoint for everyone

SharePointRyan

Ryan Dennis is a SharePoint Solution Architect with a passion for SharePoint and PowerShell

SharePoint 2020

The Vision for a Future of Clarity

Aharoni in Unicode

Treacle tarts for great justice

... And All That JS

JavaScript, Web Apps and SharePoint

%d bloggers like this: