Category: SharePoint

Add Additional Range Text to Rating Scale Survey Questions

I had a requirement to have a scale with 5 different text ranges within a survey question, by default you can only have three.

  • Strongly Agree
  • Agree (missing)
  • Neither Agree/Disagree
  • Disagree (missing)
  • Strongly Disagree

Question Settings

Before

​After

Click “Respond to this Survey” which will take you to the “NewForm.aspx” page.

Next click on “Settings” (cog) and click “Edit page”.

Add a “Script Editor” web part below your survey questions and insert the code below.

I’ve also included a few other changes which I think make a survey look a little tidier.

<style>

/* Removes Top Buttons */
table[id*='toolBarTbltop']{display:none;}

/* Removes Line */
.ms-formline {display:none;}

/* Removes Number Headings */
th.ms-gridCol {display:none;}

/* Change Main Question */
.ms-formlabel {font-weight: bold!important;}

/* Change Sub Question Options */
.ms-gridT1, .ms-gridCol {font-weight:normal!important;}

/* Change Sub Question Options Column Width */
.ms-gridCol {color:#444!important; width:110px!important;}

/* Change Sub Question Title Width */
.ms-gridT1 {padding: 0px 0px 10px 0px; width:300px!important;}

</style>

<script language="javascript" type="text/javascript" src="jquery-1.4.2.min.js"></script>
<script language="javascript" type="text/javascript" src="jquery.SPServices-2013.01.min.js"></script>
<script language="javascript" type="text/javascript">

$(document).ready(function (){

// 1st Rating Scale
$("td.ms-gridCol:eq(1)").append("Agree ");
$("td.ms-gridCol:eq(3)").append(" Disagree");

// 2nd Rating Scale
$("td.ms-gridCol:eq(6)").append("Agree ");
$("td.ms-gridCol:eq(8)").append(" Disagree");

// 3rd Rating Scale
$("td.ms-gridCol:eq(11)").append("Agree ");
$("td.ms-gridCol:eq(13)").append(" Disagree");

// 4th Rating Scale
$("td.ms-gridCol:eq(16)").append("Agree ");
$("td.ms-gridCol:eq(18)").append(" Disagree");

// 5th Rating Scale
$("td.ms-gridCol:eq(21)").append("Agree ");
$("td.ms-gridCol:eq(23)").append(" Disagree");

});

</script>
Advertisements

Get Items from Multiple Lists using jQuery & SPServices

Update: Only works for Site collection administrators

I had a requirement to collate the newest Announcements from all the sub-sites and display them onto the front page of an intranet site. I found this solution from Ben Tedder which worked but it wasn’t giving me quite the right result. So I continue my search and found this solution from Marc D Anderson, which was giving the right results but within an alert.

get-pages   get-announcements

So I decided to try and combine these two solutions into one. It starts by looping through all the sites within the collection and sees if an Announcements list exist and if there are any items within it. The CAMLQuery filters by where Expires greater than or equal to today or Expires is blank, sorts by Created descending and limited to one item. Next it builds the url to the display form (DispForm.aspx), within a dialog box and displays the results to a bulleted list.

get-items-multiple-lists

<script type="text/javascript" src="jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="jquery.SPServices-2013.01.min.js"></script>
<script type="text/javascript" language="javascript">

$(document).ready(function() {

  var listName = "Announcements";

  $().SPServices({
    operation: "GetAllSubWebCollection",
    async: false,
    completefunc: function (xData, Status) {
      $(xData.responseXML).find("Web").each(function() {
        var thisUrl = $(this).attr("Url");
        $().SPServices({
          operation: "GetListCollection",
          webURL: thisUrl,
          async: false,
          completefunc: function (xData, Status) {
            $(xData.responseXML).find("List").each(function() {
              if($(this).attr("Title") == listName && $(this).attr("ItemCount") != "0") {
                $().SPServices({
                  operation: "GetListItems",
                  webURL: thisUrl,
                  async: false,
                  listName: listName,
                  CAMLViewFields: "<ViewFields><FieldRef Name='ID' /><FieldRef Name='EncodedAbsUrl' /><FieldRef Name='Title' /></ViewFields>",
                  CAMLQuery: "<Query><OrderBy><FieldRef Name='Created' Ascending='False' /></OrderBy><Where><Or><Geq><FieldRef Name='Expires' /><Value Type='DateTime'><Today /></Value></Geq><IsNull><FieldRef Name='Expires' /></IsNull></Or></Where></Query>",
                  CAMLRowLimit: 1,
                  completefunc: function (xData, Status) {
                    $(xData.responseXML).SPFilterNode("z:row").each(function() {
                      var url = $(this).attr("ows_EncodedAbsUrl");
					  var url = url.substr(0, url.lastIndexOf("/"));
					  var fullUrl = '"' + url + "/DispForm.aspx?ID=" + $(this).attr("ows_ID") + '"';
					  var liHtml = "<li><a style='cursor: pointer;' onclick='javascript:SP.UI.ModalDialog.OpenPopUpPage(" + fullUrl + ", null, 800, 600); return false;'>" + $(this).attr("ows_Title") + "</a></li>";
					  $("#listItems").append(liHtml);
                    });
                  }
                });
              }
            });
          }
        });
      });
    }
  });
});

</script>

<ul id="listItems"/>

User Profile Synchronisation Errors In SharePoint 2013

After doing a SharePoint update at the weekend, I found that I couldn’t get the User Profile Sync to restart. It looked like it was getting to a point then failing, so I started checking the Event Viewer, found some errors and then found this article from Richard Skinner.

During testing of SharePoint 2013 I experienced the Application Event Log errors below. When the errors occurred I was unable to run a User Profile Synchronisation with Active Directory.

Event ID 6398, category Timer

The Execute method of job definition Microsoft.Office.Server.UserProfiles.UserProfileImportJob (ID 0afab701-a201-4df9-bfc7-590838da8809) threw an exception. More information is included below. Generic Failure

Event ID 1004, category None

Detection of product ‘{90150000-104C-0000-1000-0000000FF1CE}’, feature ‘PeopleILM’, component ‘{1C12B6E6-898C-4D58-9774-AAAFBDFE273C}’ failed. The resource ‘C:\Program Files\Microsoft Office Servers\15.0\Service\Microsoft.ResourceManagement.Service.exe’ does not exist.

Event ID 1001, category None

Detection of product ‘{90150000-104C-0000-1000-0000000FF1CE}’, feature ‘PeopleILM’ failed during request for component ‘{1681AE41-ADA8-4B70-BC11-98A5A4EDD046}’

The resolution is to grant read access to the Network Service account to the “C:\Program Files\Microsoft Office Servers\15.0” folder

PowerShell

$Acl = (Get-Item "E:\Microsoft Office Servers\15.0").GetAccessControl('Access')
$Ar = New-Object system.security.accesscontrol.filesystemaccessrule("NT AUTHORITY\NETWORK SERVICE","Read, ReadAndExecute, ListDirectory", "ContainerInherit, ObjectInherit", "None", "Allow")
$Acl.AddAccessRule($Ar)
Set-Acl "E:\Microsoft Office Servers\15.0" $Acl

Display a list in another site collection

The Idea

Original Post: http://blog.pathtosharepoint.com/2009/01/22/a-simple-method-to-display-a-list-in-another-site/

<!-- Load and display list - jQuery version -->
<!-- Questions and comments: Christophe@PathToSharePoint.com -->
<DIV id="ListPlaceholder"><IMG src="/_layouts/images/GEARS_AN.GIF"></DIV>
<script type="text/javascript">
// Paste the URL of the source list below:
var SelectedView = "http://domain.com/SiteCollection1/SourceSite/SourceList/MyView.aspx";
$("#ListPlaceholder").load(SelectedView+" #WebPartWPQ1 .ms-listviewtable",function() {
$("#ListPlaceholder *").removeAttr("id");
$("#ListPlaceholder *").removeAttr("onclick");
$("#ListPlaceholder *").removeAttr("onfocus");
$("#ListPlaceholder *").removeAttr("onmouseover");
});
</script>

Update: http://blog.pathtosharepoint.com/2010/04/09/cross-site-list-snapshot-version-2-0-beta/

The main improvements in version 2:
– the script now works for both lists and calendars
– there won’t be any conflict if you place several scripts on the same page
– a form helps you select your options, and includes a debugging utility

Script Generator: http://usermanagedsolutions.com/SharePoint-User-Toolkit/Pages/Cross-Site-List-Snapshot.aspx

This script allows you to display in a SharePoint page a view taken from another site or site collection. In SharePoint, the standard way to achieve this is to use a Page Viewer Web Part. Compared to a PVWP, my solution:
– looks better, as the content from the other site is integrated in the page layout
– offers less functionality, as most of the interactivity is lost in the process. This is why I am using the term “snapshot”, rather than “view”.

Display Grouped Items: http://mekalikot.blogspot.co.uk/2011/11/display-grouped-items-in-list-or.html

<!-- Load and display list - iframe version for Grouped Items SP2010-->
<div id="ListPlaceholder" style="display: none"><img src="/_layouts/images/GEARS_AN.GIF" alt=""/></div>
<!-- Paste the URL of the source list below: -->
<script type="text/javascript">
function DisplayThisList()
{
var placeholder = document.getElementById("ListPlaceholder");
var displaylist = null;
var sourcelist = document.getElementById("SourceList");
try {
if(sourcelist.contentDocument)
// Firefox, Opera
{displaylist = sourcelist.contentDocument.getElementById("WebPartWPQ2") ;}
else if(sourcelist.contentWindow)
// Internet Explorer
{displaylist = sourcelist.contentWindow.document.getElementById("WebPartWPQ2") ;}
else if(sourcelist.document)
// Others?
{displaylist = sourcelist.document.getElementById("WebPartWPQ2") ;}
}
catch(err) { alert ("Loading failed");}
placeholder.style.display = "none";
sourcelist.contentDocument.getElementById("ctl00_IplsFooter").style.display = "none";
sourcelist.contentDocument.getElementById("MSO_ContentTable").style.marginLeft = "0px";
sourcelist.contentDocument.getElementById("s4-ribbonrow").style.display = "none";
sourcelist.contentDocument.getElementById("s4-titlerow").style.display = "none";
sourcelist.contentDocument.getElementById("s4-leftpanel").style.display = "none";
}
</script>

My Revision

Before we begin, you need to make sure that the view your using has the “Basic Table” style applied (Library/List Settings > Views).

Add a “Script Editor” web part to your page and add the following script.

<script type="text/javascript" src="http://ajax.microsoft.com/ajax/jQuery/jquery-1.9.1.min.js"></script>
<script type="text/javascript">
function DisplayThisList()
{
$("#SourceList").contents().find(".ms-gb a").click(function() {
DisplayThisList();
});

$("#SourceList").contents().find("#suiteBar").hide();
$("#SourceList").contents().find("#s4-ribbonrow").hide();
$("#SourceList").contents().find(".ms-core-navigation").hide();
$("#SourceList").contents().find("#contentBox").css('margin-left','0px');
$("#SourceList").contents().find("#contentRow").css('padding-top','0px');
//$("#SourceList").contents().find("#MSOZoneCell_WebPartWPQ2").css('margin-bottom','0px');
$("#SourceList").contents().find("#Hero-WPQ2").hide();
$("#SourceList").contents().find("#titleAreaBox").hide();
$("#SourceList").contents().find("#s4-titlerow").css({'height' : '0px','padding-top' : '0px','padding-bottom' : '0px'});

$("#SourceList").contents().find("th.ms-vh").removeAttr("onmouseover");
$("#SourceList").contents().find("th.ms-vh2").removeAttr("onmouseover");
$("#SourceList").contents().find("a.ms-headerSortTitleLink").removeAttr("onclick onfocus href").css('text-decoration', 'none');

setTimeout(function(){
$("#SourceList").contents().find(".ms-subtleLink").attr('target', '_blank');
$("#SourceList").contents().find(".ms-vb2 a").removeAttr("onclick onfocus onmousedown").attr('target', '_blank');
}, 1000);

}
</script>
<ifram id="SourceList" src="http://intranet/Shared Documents/Forms/SelectedViewGroupBy.aspx" frameborder="0" onload="DisplayThisList()" width="100%" height="500"></ifram>

Note: Replace ifram with iframe (iframe are not allowed on WordPress.com for security reasons).

list-in-another-site

I hope you find my solution helpful.

Change Folder Content Type

Last week I had a request to add metadata to document library folders, thanks to this article (How to add a column to SharePoint folders) by Mike Smith I had the answer and before everyone starts I know you shouldn’t be using folders but it was the request.

Here the steps

  1. Go to Site Actions, Site Settings
  2. Click Site Content Types
  3. Click Create
  4. Give the new content type a name such as “Enhanced Folder”
  5. Set the parent content type group as Folder Content Types
  6. Set the parent content type to Folder
  7. Add the new content type to a Group. I put it back in the “Folder Content Types” group
  8. Click OK
  9. Scroll down to the columns section and click Add from new site column
  10. Name the column and set all the usual column options
  11. Repeat for any additional columns (Release Date, etc)
  12. Click OK
  13. Go to your document library
  14. Click Settings and Library Settings, or in 2010 click the Library ribbon tab and then click Library Settings
  15. Click Advanced and set Allow management of content types to Yes and click OK (this may already selected)
  16. Scroll down to Content Types and click Add from existing site content types and add your new folder content type
  17. Go to your library and click the New drop down, or the New button in the Document ribbon, and add your new folder!
  18. Go to the View drop down and click Modify this view and add your new folder meta data columns (you will probably want to move them to just after the Name column)

But, now I have my new content type, I had to update all the folders and sub folders with the new Enhanced Folder content type, PowerShell to the rescue.

$web = Get-SPWeb http://intranet/sites/test
$list = $web.Lists["Test"]
$oldCT = $list.ContentTypes["Folder"]
$newCT = $list.ContentTypes["Enhanced Folder"]
$newCTID = $newCT.ID

for($i=0; $i -le $web.Lists.Count; $i++)
{
   foreach($folder in $list.folders[$i])
   {
      if ($folder.ContentType.Name -eq $oldCT.Name)
      {
         $folder["ContentTypeId"] = $newCTID
         $folder.Update()
      }
   }
}

$web.Dispose()

Smooth Scrolling Promoted Links

I would like to start off by saying a big thank you to Thomas Kahn for doing all the hard work.

I come up with an idea to use the much-loved Promoted Links web part as a carousel. I thought that someone must have done this already, so I started with a Google search, but I couldn’t find a solution. I then started to look for away to carousel the divs within the Promoted Links web part and I found Thomas’s website http://smoothdivscroll.com.

Download: https://github.com/tkahn/Smooth-Div-Scroll/archive/master.zip

smooth-scrolling-promotedlinks

Upload all the required scripts and images, add a Promoted Links and Script Editor web parts to your page and insert the script below (update URL’s).

<style>
.ms-promlink-body {width: 90%; height: 150px; position: relative;}
.ms-promlink-header {display: none;}
</style>

<link rel="Stylesheet" type="text/css" href="http://intranet/Documents/css/smoothDivScroll.css" />

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js" type="text/javascript"></script>
<script src="http://intranet/Documents/js/jquery-ui-1.10.3.custom.min.js" type="text/javascript"></script>
<script src="http://intranet/Documents/js/jquery.mousewheel.min.js" type="text/javascript"></script>
<script src="http://intranet/Documents/js/jquery.kinetic.min.js" type="text/javascript"></script>
<script src="http://intranet/Documents/js/jquery.smoothdivscroll-1.3-min.js" type="text/javascript"></script>

<script type="text/javascript">

$(document).ready(function () {

$("div#promotedlinksbody_WPQ2").smoothDivScroll({
mousewheelScrolling: "allDirections",
manualContinuousScrolling: true,
autoScrollingMode: "onStart"
});

$("#promotedlinksbody_WPQ2").bind("mouseover", function() {
$(this).smoothDivScroll("stopAutoScrolling");
}).bind("mouseout", function() {
$(this).smoothDivScroll("startAutoScrolling");
});

});
</script>

Newsfeed for Everyone

Before

newsfeed-before

After

newsfeed-after

Copy script, save as Newsfeed.dwp and add to web part zone.

<?xml version="1.0" encoding="utf-8"?>
<WebPart xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/WebPart/v2">
<Title>Newsfeed</Title>
<FrameType>None</FrameType>
<Description>Displays conversations and event notifications from content and people you follow across SharePoint sites, and lets users send short, publicly-viewable messages.</Description>
<IsIncluded>true</IsIncluded>
<ZoneID>MiddleLeftZone</ZoneID>
<PartOrder>1</PartOrder>
<FrameState>Normal</FrameState>
<Height />
<Width />
<AllowRemove>true</AllowRemove>
<AllowZoneChange>true</AllowZoneChange>
<AllowMinimize>true</AllowMinimize>
<AllowConnect>true</AllowConnect>
<AllowEdit>true</AllowEdit>
<AllowHide>true</AllowHide>
<IsVisible>true</IsVisible>
<DetailLink />
<HelpLink />
<HelpMode>Modeless</HelpMode>
<Dir>Default</Dir>
<PartImageSmall />
<MissingAssembly>Cannot import this Web Part.</MissingAssembly>
<PartImageLarge />
<IsIncludedFilter />
<Assembly>Microsoft.SharePoint.Portal, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c</Assembly>
<TypeName>Microsoft.SharePoint.Portal.WebControls.MicroFeedWebPart</TypeName>
</WebPart>

Copy script into a Script Editor web part.

<script language="javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js" type="text/javascript"></script>

<script type="text/javascript">

$(document).ready(function() {

$("#ms-blankfeeddiv").hide();
$("#ms-shareWithDiv").hide();
$("#ms-titlebardiv").hide();
setTimeout(function() {
$("a[alt='Everyone']").trigger('click');
},1000);

});
</script>