Skip to content

Instantly share code, notes, and snippets.

@davehax
Created June 9, 2017 01:14
Show Gist options
  • Select an option

  • Save davehax/63ec95de0be3637c3ef1c5fef1fc9733 to your computer and use it in GitHub Desktop.

Select an option

Save davehax/63ec95de0be3637c3ef1c5fef1fc9733 to your computer and use it in GitHub Desktop.
function getSchemaDataForCurrentView() {
var webPartKey = '';
var webPartComponent = null;
var schemaData;
// based on the current view id we can find our way to a WPQ<number>SchemaData variable which has the goodies we need to check in it!
// First, get the web part component variable
for (var key in _spWebPartComponents) {
var a = _spWebPartComponents[key];
if (a.storageId && a.storageId == _spPageContextInfo.viewId.replace(/(\{|\})/g, '')) {
webPartComponent = _spWebPartComponents[key];
webPartKey = key;
break;
}
}
// now if we found one we can search for the SchemaData variable
if (webPartKey != '') {
// get variable name we can search window for
var partialKey = webPartKey.replace('WebPart', '');
var _schemaData = window[partialKey + 'SchemaData'];
if (typeof(_schemaData) !== 'undefined') {
schemaData = _schemaData;
}
}
return schemaData;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment