Monthly Archives: November 2015

Dynamically create subscribe to alert link JavaScript SharePoint

Code for creating an alert for a list dynamically on a page. I have created the following HTML file, upload it somewhere in your site collection and link to it from a content editor web part, change the title of the list you want people to subscribe to and the message 🙂 

Note that this is sitting on a discussion site home page therefore is looking for /sitepages – if you want it to look for /pages change this, or if you want to hard code the link to a root level list for subscription change it even more 😛 

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
</head>

<body>
<script type="text/javascript">
	$().ready(function () {
	    SP.SOD.executeFunc('sp.js', 'SP.ClientContext', function () { });
	    SP.SOD.executeOrDelayUntilScriptLoaded(initiateDiscussionsAlerts, "sp.js", "SP.ClientContext");
	})

	var discussionList;
	var discussionWeb;
	function initiateDiscussionsAlerts() {
		// load web
		clientContext = new SP.ClientContext.get_current();                    
	    discussionWeb = clientContext.get_web();
	    clientContext.load(discussionWeb);
	    
	    // load discussions list and ID
	    discussionList = discussionWeb.get_lists().getByTitle("Discussions List");
	 	clientContext.load(discussionList); 
	
		clientContext.executeQueryAsync(Function.createDelegate(this, onQuerySucceeded), Function.createDelegate(this, onQueryFailed));
	}
	  
	function onQuerySucceeded() {
		var webUrl = window.location.href;
		if (webUrl.toLowerCase().indexOf('/sitepages') != -1) {
			var listGuid = discussionList.get_id();
		    webUrl = webUrl.substr(0, webUrl.toLowerCase().indexOf('/sitepages'));
		    
		    $('.discussion-alert > a').attr('href', webUrl + '/_layouts/SubNew.aspx?List=' + listGuid + '&Source=' + webUrl);
		}
	}
	             
	function onQueryFailed(sender, args) {
		alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
	}
</script>

	<div class="discussion-alert"><a href="">Subscribe to Alerts for this Discussion Board</a></div>
</body>

</html>

 

Reporting Services SSRS in SharePoint Error ‘New Document’ requires a Microsoft SharePoint Foundation-compatible application and web browser…..

Adding SSRS content types seems to be a bit flaky.. We couldn't get the content types automatically added by activating the feature in one web application – so we manually added the content types into the site collection as specified in here (http://sharepoint.stackexchange.com/questions/111619/sharepoint-2013-sp1-installation-issue-ssrs-content-type-missing-for-new-sc) – this post also had some other good suggestions.

So we add another web app for another purpose – again same issue with the content types not adding, so we add them manually again and get the following error when trying to create an item in the document library for "Report Data Source", "Report Builder Report" and "Report Builder Model" – 'New Document' requires a Microsoft SharePoint Foundation-compatible application and web browser. To add a document to this document library, click the "Upload Document" button."

We had added them manually correctly and obviously it was installed correctly as another web app was working..

We came across this post which worked for us! https://chrishattonnzlsp.wordpress.com/2015/07/21/reporting-services-new-document-requires-a-microsoft-sharepoint-foundation-compatible-application-and-web-browser/

Running rsSharePoint.msi fixed the issue. We had to delete the content types from lists and the site collection and then deactivated and reactivated the reporting services feature, the content types were there this time and we could add the proper ones into the libraries.

Tenant Administration Delete Root Site Collection and Re-Create Doesn’t Properly Delete From Recycle Bin

I came across a strange issue when re-creating the root level tenant site collection from the interface. It's like it wasn't actually deleting the site collection – the wiki page content was on my new home page and the features activated was all wrong. Here's the steps I followed in the interface to replicate the issue:

We need to remove the root level site collection

  • Navigate to the site collections screen adminurl.sharepoint.com/_layouts/15/online/SiteCollections.aspx
  • Check the root level site site.sharepoint.com
  • Click Delete
  • Select “I understand that nobody can access SharePoint until I create a new site collection at https://site.sharepoint.com.”
  • Click Delete
  • Wait until the site is removed before continuing the release.

Create site collection

  • Click on create new private site collection in admin adminurl.sharepoint.com/_layouts/15/online/SiteCollections.aspx
  • Enter the following details:

    • Title: Title
    • Web Site Address: this should default to the root level site
    • Template Selection: Publishing -> Publishing Portal
    • Time Zone: (UTC + 12:00) Auckland, Wellington
    • Administrator: admin username
    • Server Resource Quote: leave at 300
    • Click OK
  • You will get a warning "Permanently delete the site collection from the recycle bin and continue."
  • Check the box and click OK

It obviously doesn't actually properly delete the site collection from the recycle bin. 

So I contacted Microsoft as this was annoying the hell outa me and I couldn't deploy my site into the test environment. They gave me the following instructions to get PowerShell to do the job, which is cool but slightly annoying as the release didn't require any installation of extra software and now it does, but in saying that I guess anyone who works with SharePoint should have this installed anyway :P. M$ didn't give any indications of fixing and ignored my comments regarding fixing the interface to work. 

Access Denied deploying files to SharePoint Online as Global Administrator

So I went to deploy to test and for some reason kept getting access denied errors, but I'm global admin!! and Site collection admin!! What. It died on the code where I am uploading to the master page gallery. 

The problem was I had been deploying to /sites/site and not to the root web in other tests. The root web has a setting on it called DenyAddAndCustomizePagesStatus which is set to true but on the /sites/site sites, it's set to falce :|. Even more annoying, I had alsom deployed to a demo tenant under the root web and this works, so I can only assume since it's a demo tenant with content that Microsofts code actually does this for you… https://support.office.com/en-us/article/Turn-scripting-capabilities-on-or-off-1f2c515f-5d7e-448a-9fd7-835da935584f?ui=en-US&rs=en-US&ad=US

Here's the code for deactivating on your site collection. Thanks to Ronny Lewandowski and SPMeta2 for helping me to solve this issue :). 

static void Main(string[] args)
{
            string siteUrl = ConfigurationManager.AppSettings["SiteUrl"];
            string adminUrl = ConfigurationManager.AppSettings["AdminUrl"];
            string userName = ConfigurationManager.AppSettings["AdministratorUserName"];
            string password = ConfigurationManager.AppSettings["AdministratorPassword"];
            var securePassword = new SecureString();
            foreach (var c in password) { securePassword.AppendChar(c); }

           Console.WriteLine("Start: Allow customisations...");
           DisableDenyAddAndCustomizePages(adminUrl, siteUrl, userName, securePassword);
            Console.WriteLine("End: Allow customisations... \n");
}

public static void DisableDenyAddAndCustomizePages(string adminUrl, string siteUrl, string userName, SecureString securePassword)
        {
            using (var ctx = new ClientContext(adminUrl))
            {
                ctx.Credentials = new SharePointOnlineCredentials(userName, securePassword);

                Tenant tenant = new Tenant(ctx);
                var siteProperties = tenant.GetSitePropertiesByUrl(siteUrl, true);
                ctx.Load(siteProperties);
                ctx.ExecuteQuery();

                siteProperties.DenyAddAndCustomizePages = DenyAddAndCustomizePagesStatus.Disabled;
                var result = siteProperties.Update();
                ctx.Load(result);
                ctx.ExecuteQuery();
                while (!result.IsComplete)
                {
                    Thread.Sleep(result.PollingInterval);
                    ctx.Load(result);
                    ctx.ExecuteQuery();
                }
            }
 }

ALSO, here is the code in PowerShell if you just want to quickly run it once:

Clear-Host
$spOnlineUser = ''
$spOnlinePassword = ''
$spOnlineSiteAdminUrl = ''
$spOnlineSiteUrl = ''
 
$cred = New-Object -TypeName System.Management.Automation.PSCredential -argumentlist $spOnlineUser, $(convertto-securestring $spOnlinePassword -asplaintext -force)
Connect-SPOService -Url $spOnlineSiteAdminUrl -Credential $cred
Write-Host "Connecting to " $spOnlineSiteUrl
 
$site = Get-SPOSite -Identity $spOnlineSiteUrl
Write-Host "Connection Successful!!" -ForegroundColor "Green"

Set-SPOSite -Identity $spOnlineSiteUrl -DenyAddAndCustomizePages 0

Write-Host "Finished!!" -ForegroundColor "Green"