Quantcast
Channel: Automate IT! » javascript
Viewing all articles
Browse latest Browse all 9

How-to run Custom JavaScript script. Script: Get IDs of all web site lists (included hidden ones)

$
0
0

Case:

You need to determine list of all Sharepoint lists available on site. Of course, we may use “View All Site Content” (“Site Actions” –> “View All Site Content”) menu item, but it doesn’t show hidden lists used on site (e.g. Workspace Pages inside Meeting Workspace Site Template).

With names of lists you’ll probably need to get their IDs to get access for list properties using URL.

So, I offer you to run JS-script for all this purposes.

How-To run script:

1. Use HTML Form Web Part

2. Run script in IE.

For this operation, please, use developer tools in IE ( IE 8 and older).

Note: In spite of IE 7 has Developer Tools too, it distributed separately of main package and don’t offer to run scripts.

To run script choose “Script” tab, put script into MultiLine TextBox and click “Run Script”.

image

Script:

This example may be run inside HTML Form web part.

To run this code inside IE Developer Tools please exclude code lines marked with blue color and make call to function ‘retrieveAllListProperties();’  after all lines of code:

<script type="text/javascript">

function retrieveAllListProperties() {
    var clientContext = SP.ClientContext.get_current();
    var oWebsite = clientContext.get_web();
    this.collList = oWebsite.get_lists();
    clientContext.load(collList);

    clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
}

function onQuerySucceeded() {

    var listInfo = ”;

    var listEnumerator = collList.getEnumerator();
    while (listEnumerator.moveNext()) {
        var oList = listEnumerator.get_current();
        listInfo += ‘Title: ‘ + oList.get_title() + ‘ ID: ‘ + oList.get_id().toString() + ‘\n';
    }
    alert(listInfo);
}

function onQueryFailed(sender, args) {
    alert(‘Request failed. ‘ + args.get_message() + ‘\n’ + args.get_stackTrace());
}

ExecuteOrDelayUntilScriptLoaded( retrieveAllListProperties , "sp.js");

</script>

Some links:



Viewing all articles
Browse latest Browse all 9

Trending Articles