Javascript to open SharePoint links list items in a new window

This is harder than it sounds, mostly because of the way SharePoint renders it pages and links within. If you are displaying a links list on a page and it is GROUPED using metadata, then you are going to have a bit of a tough time accessing those links using Javascript. The key is to use SharePoint’s version of the

$( document ).ready “trigger” called¬†_spBodyOnLoadFunctionNames.push

Below is some code I used which worked nicely. There is a bit of output you can remove once you see you are getting the results you want. ūüôā Just add into a CEWP on the same page (or MP ref).Add you script tags to ref jQuery lib and surround JS below:

function sharePointReady()
{
updateLinks();

//Hook into SharePoint event to fix all links in group-by tables.
var oldExpand = ProcessImn;

ProcessImn = function(){
var results = oldExpand.apply(this, arguments);

updateLinks();

return results;
}
}

function updateLinks()
{
var url = ‘://’ + window.location.hostname;
$(“a”).each(function() {
var link = this; // assign the link object to another variable for easier managability
var linkHref = link.href.toLowerCase(); // lower case it
console.log(url);
console.log(linkHref);
if(linkHref.indexOf(url) < 0 && linkHref.indexOf(‘javascript:’) 0){ // check to see if this is a PDF
link.target = ‘_blank’; // change the target to be in the new window
$(link).removeAttr(“onclick”); //remove the SP click event
}

if(linkHref.indexOf(‘/forms/’) > 0 && linkHref.indexOf(‘).aspx’) > 0){
//check for links in the forms library
link.target = ‘_blank’; // change the target to be in the new window
$(link).removeAttr(“onclick”); //remove the SP click event
}
});

}

//this is the SharePoint preferred alternative of $(document).ready
_spBodyOnLoadFunctionNames.push(“sharePointReady”);

 

Search has encountered a problem that prevents results from being returned

I found this error while testing a search result source in a ported SharePoint 2013 site (to SharePoint 2016): Search has encountered a problem that prevents results from being returned. If the issue persists, please contact your administrator.
When I looked through the ULS there was a number of errors relating to the result source’s query. The issue, of course, was that I hadn’t reset the search index and done a full crawl since migrating and upgrading the content database.
Problem solved!

CAML Query using Date Ranges

Having trouble getting any results back when querying a SharePoint list for items within a date range? It may be that you haven’t converted your variable dates to the ISO 8601 format that SharePoint expects for date values in CAML queries. You can do this by using the SPUtility.CreateISO8601DateTimeFromSystemDateTime()¬†method. Make sure the dates you are converting are in UTC or local time first though!

An example is below:

string Iso8601startDate = SPUtility.CreateISO8601DateTimeFromSystemDateTime(startDate);

string Iso8601Today = SPUtility.CreateISO8601DateTimeFromSystemDateTime(DateTime.Today.AddDays(1));

            if (spList != null)

            {

                SPQuery qry = new SPQuery();

                qry.Query =

¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†@”¬†¬† <Where>

                          <And>

                             <Gt>

¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬† <FieldRef Name=’DateSubmitted’ />

¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬† <Value Type=’DateTime’ IncludeTimeValue=’FALSE’>”¬†+ Iso8601startDate +

¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†@” </Value>

                             </Gt>

                             <Lt>

¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬† <FieldRef Name=’DateSubmitted’ />

¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬† <Value Type=’DateTime’ IncludeTimeValue=’FALSE’>”¬†+ Iso8601Today +

¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†@”</Value>

                             </Lt>

                          </And>

                       </Where>

                       <OrderBy>

¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬† <FieldRef Name=’DateSubmitted’ />

¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬†¬† </OrderBy>”;

 

 

 

Getting Values from a Multi-select People Picker in VS Workflow

If you are trying to get a value from a multi-select people picker in workflow in the same way as you would from a single select people picker, then you are going to have problems.

I came across a great post (my salvation) here:

http://sharepoint.stackexchange.com/questions/78125/workflow-sp-2013-cannot-retrieve-a-usermulti-field-value

-which saved me a lot of time and headache. But just incase ¬†I’ve posted a screenshot below. Worked a treat for me (in this example, the multi-select people picker field is called Members).

MultiPPValueWF

Error When Creating Links List Items (Hyperlinks)

In my case, I was using PowerShell to create a bunch of links to folders on a file-share in a SharePoint list. I came across errors when I used the 2010 method in 2013. Below I have provided examples of each method:

2010

$urlValue = New-Object Microsoft.SharePoint.SPFieldUrlValue("")
$urlValue.Description = "This is an awesome description"
$urlValue.Url =  "http://MyUrl.com"
$item["URL"] = $urlValue
$item.update()

2013

$newItem = $list.Items.Add()
$newItem["URL"] = "$urlString , $descriptionString"
$newItem["Comments"] = $descriptionString
$newItem.Update()

 

Display a List Web Part View Using a Query String Parameter

So what if you want to have a single “dashboard” page that displays a number of web parts, including a list web part? You’d like to provide multiple links to the page which will display slightly different views of the information. In this case, you may want to think about using the view query string parameter in your links to change the view of the list web part displayed.

To get a list view GUID/s add the list web part to your page and filter the list. You can then look at the URL to find the GUID, e.g. https://server/sites/subsite/Shared%20Documents/Dashboard.aspx?View={CEF00598-91B2-456E-8068-F351BC9CC1BA}

Change the web part View property to access different view GUIDs. Once you have a GUID for each view, you can add the ? or & View={GUID} to your dashboard hyperlinks.

Click the hyperlinks and bingo-bango, you should see your list web part displays the relevant view. This should not effect any other web parts also on the page, as the view GUID is unique to the specific list.

 

Grouping a List View by a Calculated Date Field

If you’ve been ultra efficient and create a calculated Date Field that will display the month and year (e.g. Aug¬†2015) of a date column so that you can group something like News Articles in this way, you may have already discovered that grouping your list view using this new column displays the group header as blank. When you include the calculated field in your view, you see it has value BUT the won’t display in the group header.

I found a work around for this – simply edit your view and change the style to Basic Table. I also played around with default expansion of the groupings. This should now display your calc field group headings and display any items underneath.