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”);

 

MIM 2016 Issues and Essentials

Ok, so recently I have been configuring the SharePoint 2016 connector with Microsoft Identity Manager 2016. MIM replaces FIM 2010 R2 for SharePoint profile synchronisation with AD and/or other providers (it also does a bunch of other stuff but I’m focusing on Sync only here). In SharePoint 2016, you can still your the embedded AD sync function if you like, but remember that is uni-directional (pull from AD) only. In my case, I need to push some properties set in the SP profiles into AD as well.
To save you some time, here are some tips for getting MIM syncing SharePoint profiles:

Use the PnP provided toolkit BUT make an update to the ps module file. You need to update lines 81 and 82. And don’t forget to reload the module after making the changes.


if ($MimPowerShellModuleAssembly.VersionInfo.ProductMajorPart -eq 4 -and
$MimPowerShellModuleAssembly.VersionInfo.ProductMinorPart -eq 4 -and
$MimPowerShellModuleAssembly.VersionInfo.ProductBuildPart -ge 1237)
{
Write-Verbose “Sufficient MIM PowerShell version detected (>= 4.4.1237): $($MimPowerShellModuleAssembly.VersionInfo.ProductVersion)”
}

This is a pretty good blog to follow for setting up the whole process:
https://thesharepointfarm.com/2016/03/basic-mim-configuration-support-sharepoint-2016/

Now, if for any reason the hookup fails (using these tools), you need to get a fresh copy of the ADMA files (XML) before re-running. Else you are going to get errors like:¬†The property ‘name’ cannot be found on this object. Verify that the property¬†exists and can be set.

This is a good post that explains it: https://social.technet.microsoft.com/wiki/contents/articles/33816.error-during-the-installation-of-sharepoint-server-configuration-file-user-profile-service-mim.aspx

Make sure you understand the basics about MIM before you begin, namely what the Metaverse and Connector Spaces refers to and the difference between Import, Sync and Export.

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.