Thoughts on SPScriptAudit

Coordinator
Jan 19, 2010 at 6:19 PM
Edited Jan 19, 2010 at 6:21 PM

I had a chance today to sit down and really review the SPScriptAudit function in the new 0.4.8 release. I'll pen a few thoughts on the function (a mix of general observations and ideas to consider moving forward). As Marc pointed out in his blog post, the SPScriptAudit function is really in its infancy, but is (in my opinion) an excellent starting point for a nicely integrated script audit capability. As someone who maintains many different SharePoint sites, this type of solution can potentially save a lot of time when built into a tool that can be deployed across all sites.

  • What if my scripts aren't in a document library/list?
    As an example, for my testing purposes I created a file in the root of my SharePoint site, next to default.aspx called scriptaudit.aspx. The function seemed to find all files within lists and within document libraries, as advertised, but it listed my default.aspx and scriptaudit.aspx files as being in one of the site lists, and with a page class of "View".
  • Recursive Site Scope?
    In my application, and I'm sure also valuable to others, I'd love to be able to run a report of all script usage within a collection. Obviously I could easily do that by using the GetWebCollection or GetAllSubWebCollection web service to call SPScriptAudit for each site, however I wonder if a recursive option in the SPScriptAudit function itself may suit the function. Perhaps recursive from the specified webURL, as opposed to recursive to the entire collection, giving the user some flexibility. This would of course add the need for a "URL" or "Site Name" field in the output table to show which site the code was found in.
  • Code Formatting
    This is more personal preference on the actual output of the function, but I wonder about outputting the script into a larger jQuery popup, displayed with a "view script" button in the table, much like the debug output that's built into SPServices. As the output grows, say if you did a full recursive search on a collection with 10 subsites, the output table could become pretty cluttered with all of the text fields containing code. Taking that a step further, if the popup was an option--some type of code formatting with line numbers of the script and color coding might also be a nice touch. I can't tell you how many times I refer back to code I've written somewhere else to help me build new projects, I could see this function assisting in those activities also.
Coordinator
Jan 20, 2010 at 5:43 PM

One last suggestion:

Sometimes, depending on where you're running it and how much is on the site, the script takes a while to run. It might be a nice add to have a completefunc type capability that fires when the script is done going through everything. Then I could write a loading message into a div at the start, and use completefunc to remove the message when I know the script it done running.