Before I describe the problem, I want to clarify that what I'm looking for is A generic way of updating various attributes/properties using JSOM.
I'm using an Office 365 dev account testing a SharePoint 2013 app. I'm trying to use JSOM to change a list column's attributes. Maybe I'm missing something here but what's the trick using JSOM on SharePoint 2013 to get/set specific list field attributes? For instance, I want to change the "Show field" in an "Attendees" column in a OOTB calendar list to be "Work email" instead of "Name (with presence)".
Before you jump the gun and tell me about get_Title() and get_required() and the other built in functions, let me clarify that I'm looking for something more generic where I can specify the exact attribute that maybe doesn't have a built-in function (like the "Show Field" example above).
I've tried using the get_schemaXml()
and set_schemaXml()
functions to get/set the XML directly like Anatoly Mironov does in his post. While this doesn't kick back errors, it also doesn't update anything. Does Office 365 even allow overwriting of XML schemas? Or is something out of whack w/ my code:
function testColPropChange(listName, fieldName, newTitle) {
var subSiteUrl = 'https://tester.sharepoint.com/testSub';
this.context = SP.ClientContext.get_current();
var appContextSite = new SP.AppContextSite(this.context, subSiteUrl);
this.web = appContextSite.get_web();
var oList = this.web.get_lists().getByTitle(listName);
var field = oList.get_fields().getByInternalNameOrTitle(fieldName);
this.context.load(field, "SchemaXml");
this.context.executeQueryAsync(Function.createDelegate(this, loadSuccess), Function.createDelegate(this, errorHandler));
function loadSuccess() {
var schema = field.get_schemaXml();
var s1 = schema.replace('Required=/"FALSE/"','Required=/"TRUE/"');
field.set_schemaXml(s1);
field.update();
this.context.executeQueryAsync(
Function.createDelegate(this, schemaChanged),
Function.createDelegate(this, errorHandler));
}
}
It's a simple query but I could still have jacked it up somewhere.
There has to be a simpler way of updating list column attributes using JSOM. Please advise.
======= UPDATE =========
While Rob's solution works for the instance I discussed above, I'm reopening this thread b/c I think it deserves more discussion.
I have many different properties other than the one mentioned that I can't seem to find a way to update (no native get/set methods). I've run across several but the two that I can remember off the top of my head are:
- "SelectionMode" (aka UserSelectionScope) on a people field
- "NavigateForFormsPage" on any list (to open forms in dialog instead of new page)
These props can be easily modified using C# or PowerShell with simple dot notation, so one would think it would be easy to change these in JSOM as well. But intellesense doesn't find anything. So what's the equivelant of obj.prop in JSOM? Anybody? Buehler... Buehler...