Enable SharePoint Read only columns of List/Library

Enable SharePoint Read only columns of List/Library


Some times under SharePoint List/Library settings columns are not enabled(Greyed out) to edit or delete.

Using below jsom code we can enable the readonly columns.
For this you need to proide below inputs
1.List Name
2.ContentType ID whitch the column is associated
3.Any substring of column name (example: If column name is 'Country Name' -> you can type 'Country')


Here we can get the content type id from list settings if we click content type from URL we can get content type ID

We need to add Script editor web part & insert the below code.

<html>
AnySubStringofColumnName:<input type="text" id="txtColName"/><br/><br/>
ListName:<input type="text" id="txtListName"/><br/><br/>
ContentTypeID:<input type="text" id="txtContentType"/><br/><br/>
<input type="button" value="Update" onclick="enableSPLibraryColumnsIfDisabled()"/>
<html/>


<script>
//using this funciton to Enable Sharepoint library disabled columns
function enableSPLibraryColumnsIfDisabledCt1()
{
var context = new SP.ClientContext.get_current();
var web = context.get_web();
var list = web.get_lists().getByTitle(document.getElementById('txtListName').value);
var ct = list.get_contentTypes().getById(document.getElementById('txtContentType').value); // Content type - Trace
var fields = ct.get_fields();
context.load(fields)
context.executeQueryAsync(printFieldNames, onError);
function printFieldNames() {
var e = fields.getEnumerator();
while (e.moveNext()) {
var f = e.get_current();
//console.log(f.get_typeAsString());
//console.log(f.get_title());
//console.log(f.get_fieldTypeKind());
if((f.get_title()).indexOf(document.getElementById('txtColName').value)>=0)
{
if(f.get_readOnlyField() == true)
{
f.set_readOnlyField(false);
f.update();
context.executeQueryAsync(function(){console.log('success');}, onError);
}
}
}
}
function onError(sender, args) {
console.log(args.get_message());
}
}
</script>

Comments

Popular posts from this blog

Upload Single/Multiple file by using the REST API and jQuery SharePoint 2013

Add content type to SharePoint List/Library using REST API

A type named 'SP.Data. could not be resolved by the model error