SharePoint How To: Change a field’s JSLink property using JSOM


Whether you need to update the .js file and want browsers to automatically download the new version (skip local cache) or you need to completely change the script, here’s how you can achieve this in your browser’s console:

const listUrl = '/sites/siteName/Lists/List';
const fieldTitle = 'My Field';

const clientContext = SP.ClientContext.get_current();
const web = clientContext.get_web();
const list = web.getList(listUrl);
const field = list.get_fields().getByInternalNameOrTitle(fieldTitle);

clientContext.executeQueryAsync(
	() => {
		console.log(fieldTitle, "'s JSLink: " + field.get_jsLink());

		// set new JSLink:
		if (false) {
			const newJSLink = 'NEWJSLINK HERE';
			field.set_jsLink(newJSLink);
			field.update();
			clientContext.executeQueryAsync(
				() => {
					console.log(`Successfully set JSLink for field ${fieldTitle} to ${newJSLink}`);
				},
				(sender, error) => {
					console.error(error.get_message);
				}
			);
		}
	},
	(sender, errror) => {
		console.error(errror.get_message());
	}
);

 

While viewing any list in your SharePoint site, open the console, add your list url and field title and first run the script to see the current JSLink and then remove the `false` branch to change it.