Recently I’ve been doing some 2010 work on a site which needed a bunch of javascript and some CSS files. Now most of these were deployed to the style library but as you know you often have to check them in etc once deployed.

Rather than figure that out I thought I’d just give a message to the user on activation of the feature

It works. Is it proper ? eerrrr maybe not. but its centainly interesting.

First I have a sandbox solution, in it are the things I required. Also in it is a Hidden feature that all the other features have as an activation dependency.

If any of the other features are activated then my hidden feature is also activated.

This hidden feature contains a CustomAction with a scriptlink in it.

So as the hidden feature is activated at the same time as the parent features (likely before as its a dependancy)the javascript in the scriptlink gets rendered to every page on sharepoint from that second onwards.

The person who activated the feature will likely be the very first to get it. But this code caters for the fact that anyone could execute doing this, but only matters if they are on the managefeatures page, but relies on the incredibly unlikely scenario that two different people are accessing the managefeatures.aspx page at the same time and that they have the correct rights. Very very unlikely.

So the features is activated, the hidden feature is activated, the javascript is rendered to the page for every user but only applies on the managefeatures page, thats the page you are on when you clicked activate feature.

Now the person who just activated that feature gets to run the code which checks to see if they are on the managefeatures pages, then determines if they have the correct rights, it then de-activates the hidden feature, (a feature that de-activates itself, slightly mad).

On successful de-activation (using jsom) the javascript then pops up the messages telling the user that there is some more work to do now you have activated the feature. They can click on the link I provided in the notification too to go there and do it, this example is in the style library but you could have deployed a custom settings page.

One navigating away, because the feature de-activated itself, that javascript code that send the notification no longer exists so wont appear again. Of course, if you have your own custom settings page then that page could de-activate the feature so that every time someone is on the features page the notification appears reminding them that the feature they activated is not properly configured, that would be much better of course, in fact with a custom settings page then you could have the notification appear on every page instead of just features provided you have the correct rights.

So heres the javascript

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="">

  <CustomAction Location="ScriptLink" ScriptBlock="

(function() {
                var pageName=location.pathname.substring(location.pathname.lastIndexOf('/') + 1).toLowerCase();

                if (pageName === 'managefeatures.aspx')
                    ExecuteOrDelayUntilScriptLoaded(CheckUserPermissions, 'sp.js');
                var web;
                var site;
                var context;
                function CheckUserPermissions() {
                    context = new SP.ClientContext.get_current();
                    site = context.get_site();
                    web = site.get_rootWeb();
                    context.load(web, 'EffectiveBasePermissions');
                    context.executeQueryAsync(Function.createDelegate(this, RemoveFeature), Function.createDelegate(this, OnFailSiteFeautres));
                function RemoveFeature () {
                  if (web.get_effectiveBasePermissions().has(SP.PermissionKind.manageWeb)) {

                    this.feats=site.get_features().remove('ja7c79dd-7fa5-456d-9af8-867ed3f9303a',  false)
                    context.executeQueryAsync(Function.createDelegate(this, OnSuccessSiteFeatures), Function.createDelegate(this, OnFailSiteFeautres));
                function OnSuccessSiteFeatures(sender, args) {
                    notifyId = SP.UI.Notify.addNotification('You need to now visit the &lt;a href=&quot;' + L_Menu_BaseUrl + '/Style Library/js&quot;&gt;Style Library&lt;/a&gt; to check in the new files', true);

                function OnFailSiteFeautres(sender, args) {
                    notifyId = SP.UI.Notify.addNotification('You need to now visit the style Library to check in the new files', true);
                    statusId = SP.UI.Status.addStatus('Feature Activation Messaging problem. Arrange a manual feature deactivation with the support team ID ja7c79dd-7fa5-456d-9af8-867ed3f9303a');
                    SP.UI.Status.setStatusPriColor(statusId, 'red');
                Sequence="9999" />