Category Archives: JS Link

SharePoint Fest Chicago – December 2018

Are you attending #SPFestChi SharePoint Fest – Chicago next week? I’ll be presenting a workshop on Monday and sessions Wednesday through Friday. Mostly talking about the intersection of SharePoint and PowerApps but also talking some legacy client-side rendering for SharePoint ‘classic’ as well.

  • WRK302 – Introduction to Building PowerApps for SharePoint Users
  • PWR104 – PowerApps: New Approaches to the Traditional SharePoint List View
  • PWR202 – From SharePoint to PowerApps: Evolution of the ‘Intake Form’ Solution
  • PWR303 – Client-Side Rendering (CSR) for SharePoint: from Intro to Practical Application

Let me know if you have any questions about my sessions and hope to see you there!

JS Link – Add Ellipsis to a Column

Ran across a random request the other day to see the ellipsis menu added to a column other than the Title column. Turns out it’s a pretty simple change similar to how we change the column header text in a SharePoint view.

listItemMenu = “TRUE”

See the full code HERE.

Note: To remove the ellipsis from the Title column in the view, change the column from “Title (linked to item with edit menu)” to “Title” field in the view Columns.

References

Note and Disclaimer: JS Link currently works in SharePoint 2013, 2016, and SharePoint Online. JS Link does NOT work with the ‘Modern Experience’ interface – only Classic Mode. See ‘Choose Your Path Forward’ for more information.

JS Link – No More HTML in Calculated Field Change

Didn’t see that coming.

More than a few times I’ve had folks bring up solutions using calculated fields to do some of the same things we do with Client-side rendering (CSR) and JS Link in SharePoint. That was fine at the time. Just another way to get to the solution using creative out of the box capabilities – until now.

Microsoft implemented a change yesterday (June 13, 2017) that HTML or script elements in calculated fields would be turned off. Apparently this was an ‘undocumented use’ of the feature. The system is now escaping special characters and replacing the column with a blank in the list view.

Now What?

The short answers – in no particular order:

  1. Client-side rendering via JS Link property of web parts. This only works for Classic mode. If you are using Classic mode, this is likely the ‘best’ short term answer to broken interfaces until a longer-term solution is implemented
  2. Third party products
  3. SPFx Extensions or customization
  4. PowerApps

CSR and JS Link: There are multiple ways to implement JS Link, some via the browser (how I use JS Link) and via deployed coded solutions (Dev only). As mentioned in other responses JS Link does NOT work in the modern experience. It will only work in the Classic mode (as long as it is around). There have been NO dates announced for getting rid of Classic mode at this time. If you choose this direction it’s worth noting that if you’re comfortable writing script in the calculated field you’ll likely be comfortable writing the code needed to get CSR to work. I’ve got plenty of examples in the link included here.

Third party products. I’ve seen folks mention something called Skybow but I’ve never seen or used it. Only mentioning because it was mentioned by someone in the community I trust.

SPFx Extensions and customizations: This is the ‘approved’ development path for deployed solutions. If you are a developer and/or are creating solutions that are used across a broader scope this is likely the path you should go down.

PowerApps: This is likely the long-term replacement for solutions you used HTML or other scripting in your calculated field for (hand slap from English teacher). Embedded integration with SharePoint isn’t there yet (well, it kind of is…), but has been announced. You can start building the views/solutions you need, but they won’t be ‘really’ embedded in SharePoint yet – web parts and/or other tools are coming soon (they’ve been announced).

Note: Much of the attention to PowerApps has been in the area of forms, but views will be a part of the capabilities as well. They’ve already made improvements with introduction of controls like the Data Table control. Check out my posts on PowerApps for SharePoint users, specifically things like ‘List View’ Layouts.

Update

Migration Note: Do not forget to take this into consideration now as something to look at when migrating from an environment where special characters (HTML and scripting) work into an environment (O365, etc.) where they do not. You’ll need a plan to replace or update your field customizations.

Summary

Unfortunately this seems like a pretty sudden change. I certainly had no idea it was coming. For folks that were using this approach there’s a lot of scrambling going on right now dealing with blank columns that weren’t blank a few days ago. Depending on how complex the scripting was, some fixes might be as easy as stripping the HTML and script out and displaying a simple value. More complex solutions are going to take some effort to redo, either with a new approach, new code, or 3rd party software to get the business functionality back.

For simple HTML replacement, JS Link could be an easy switch. If you’ve never used it before check out the Hello World post and then the KPI post. Those will cover a lot and introduce you to the JS Link concept if you need to dig deeper for more complex solutions.

Good luck!

References

PowerApps – No Items to Show

In a previous JS Link / CSR post we covered how to handle what is displayed in a web part when there are no items to show. SharePoint’s default message is an ambiguous:
“There are no items to show in this view of the [listname] list”

Not an awesome user experience. Something a little more contextually relevant might be more helpful to users – either in a simple list view, or in a more complicated solution.

A PowerApps Gallery control isn’t any better – merely showing a blank record. The Data Table control, on the other hand, has a handy ‘NoDataText’ property that can be configured to display a message when the control is empty. 

So, what do we do when using Gallery controls – until a ‘NoDataText’ property is added and/or the Data Table control allows for more configuration options? As is the answer with many things in PowerApps: We use a formula.

Using an appropriate text field control within a Gallery control, we can replace the Text property with a formula like the following:

If(CountRows([_List Name_])=0,”[_Put your message here_]”, ThisItem.Title)

For a SharePoint list named: DefaultList you get the following:

If(CountRows(DefaultList)=0,”Nothing to see here”, ThisItem.Title)

The ‘CountRows’ function as you might guess returns the number of rows in the list.

The ‘If’ function tells the control to set the displayed value of the control to “Nothing to see here” if the condition (there are 0 rows) evaluates to ‘true’. If not, the value of the control is ThisItem.Title – the normal field value we would expect in the control. The text is only displayed when there are no items in the list. 

That’s it. Smile 

References

JS Link – Creating Custom Links

I’ve spoken about this topic so many times I keep forgetting that I haven’t put together a decent post on the subject even though I’ve had sample code posted for quite some time (see References below). Smile with tongue out In my opinion, after conditional formatting this is a sweet spot for JS Link use cases and functionally WAY more useful.

Disclaimer: For those of you using SharePoint 2013, this is still relevant content. If you are using SharePoint 2016 or O365 and have PowerApps available and/or are only using ‘modern’ pages and views there are other potential solutions for you.

Business-wise, what makes custom links useful is the ability for users to build solutions – ‘stitching’ together SharePoint functionality into productive business solutions – beyond what the out of box lists and libraries provide.

What makes custom links with JS Link in SharePoint so useful is the crossing of a few core bits of functionality in SharePoint – that we’ll cover in more detail in this article:

  • Most everything in SharePoint is available via a URL – so we can ‘decode’ the links SharePoint uses to build our own links to the data we want our users to get to
  • ‘Source’ data passed through the querystring allows us to control where the user is taken after a form is used (assuming the link destination was a form – it doesn’t have to be)
  • Creating a HTML link tag is super easy

User Experience Tweaking

You can use CSR to build ‘web-user-friendly’ vs. ‘SharePoint-user-friendly’ user interfaces. If all your users are familiar with SharePoint this isn’t a compelling reason. However, for environments where non-office workers (warehouse, production, etc.) are using SharePoint sites and solutions, making the interface intuitive – making it more ‘web-friendly’ – is a compelling reason to look at enhancements like this. For example:

Non-SharePoint users don’t know what the ellipses (…) are. They don’t know they need to click on the ‘…’ to get a menu for more details, etc.
image

By adding a column with web links to forms, it makes the interface easier to navigate – the useful links are displayed prominently instead of inside of a menu that needs to be opened first. If you had custom forms this same approach could be used to get the user to those forms instead of the default forms. SharePoint only enables linking to the default forms in the interface.
image

This also gives the solution owner more control over the interface by only displaying the controls they want made available to users.

How-To

If you use the SharePoint menu to navigate to the Edit page and look at the URL you will see something like this:

https://forgegroup.sharepoint.com/TeamSite/CSR/Lists/DemoList/EditForm.aspx?ID=1&Source=https%3A%2F%2Fforgegroup%2Esharepoint%2Ecom%2FTeamsite%2FCSR%2FSitePages%2FDemo%2520-%2520Link%2520to%2520Pages%2520and%2520Forms%2Easpx&ContentTypeId=0x01004578E7B0B3F1BE41A0EE6CF023F4518D

If we break the URL down we get the following:

  • https://forgegroup.sharepoint.com/TeamSite/CSR/Lists/DemoList/EditForm.aspx
    This is the URL for the form page
  • ?ID=1
    This is the parameter passed in that tells the form which item ID in the list to display
  • &Source=https%3A%2F%2Fforgegroup%2Esharepoint%2Ecom%2FTeamsite%2FCSR%2FSitePages%2FDemo%2520-%2520Link%2520to%2520Pages%2520and%2520Forms%2Easpx
    This tells SharePoint where to navigate when the form is submitted or cancelled – essentially where the user ends up next. This can be VERY useful when building your own solution.
  • &ContentTypeId=0x01004578E7B0B3F1BE41A0EE6CF023F4518D
    Finally, this is the content type for the item in the list. We aren’t using this information for our example.

What we’re doing with the CSR code is creating our own link that will be displayed in an overridden column. The complete sample code can be found in the CSR_CustomLinks.js file. We’ll just look at the key lines here:

image

  • The link is going to ‘../Lists/DemoList/EditForm.aspx’ where ‘DemoList’ is the name of my list and ‘EditForm.aspx’ is the default edit form created for the list. If you’ve created a new form (with SharePoint Designer, etc.) and want to use it, this is where you’d put the name of the file. You could even leave the default ‘edit’ form as default but use this link to get to a separate edit form.
  • ‘ID’ is the name of the parameter we’re sending to the form. We’re getting the data from the list as ctx.CurrentItem.ID
  • Then comes our own ‘Source’ value to tell SharePoint where to navigate after the form has been used. This can be helpful if you want to direct users to a specific place other than where they came from.
  • Finally, ‘Edit’ is the text that will displayed as the link. You can use whatever verbiage makes sense to your users here OR replace the text with a graphic or icon.

In the sample code I’m actually building two links – ‘Edit’ and ‘Details’ in the same column override.

Get creative with this. The link doesn’t have to be to a form for the current list. It could be a view for another list with a reference back to the current list. For example you might have a document library where you’re keeping reference documents for a list and use a reference ID field in the document library to connect back to the current list. You could use this CSR approach to build the URL string to a view of the document library and filter it by the reference ID… Then a user could be looking at the current list and click on a simple link to all the related documents for that item.

Notes

  • Using graphics: Choose a location for any graphics you want to use as part of your solution. A good place might be the SiteAssets library. Then use code that looks something like this:
    image
    Replacing the ‘Edit’ text with an HTML image tag linking to your image file.
  • Combine this link with conditional formatting and potentially display different actions or icons depending on the content of your list item.
  • Filtering on a lookup column is another post using a similar custom link approach.
  • PowerApps: Moving forward solutions like described in this post will be accomplished using PowerApps. If you’re already using SharePoint Online, the capabilities are already available by building not only a list view from a SharePoint list, but being able to customize each column and build custom forms that you can link to within your PowerApp.

References

JS Link in SharePoint – Choose your Path Forward

Times they are a changin’…

Microsoft continues to roll out the new ‘modern’ interfaces within the SharePoint platform. This is happening initially with SharePoint Online, but is also coming to on-premises deployments with SharePoint 2016 and Feature Packs. While this is a good thing for end-users overall, it does come with a price when it comes to customization options and JS Link. The new interface – the new approach – locks down client-side customizations and unmanaged code in a bid to increase the stability of the platform.

I should clarify that the JS Link approach I’m talking about is the one I’ve been working with and sharing the past few years: Using the JS Link web part property in the web interface and uploading JavaScript files via the browser. This is different from the JS Link approach used by ‘real’ SharePoint developers accessing JS Link via managed and deployed solutions. 

Classic Mode

The JS Link approach we’ve been using is still available through ‘Classic Mode’. Microsoft has stated that Classic Mode isn’t going away any time soon.

image

This means we can continue to develop solutions and customizations using JS Link and Client Side Rendering (CSR) for the foreseeable future.

Downsides of continuing to use JS Link in Classic Mode are: While the ‘modern’ and ‘classic’ interfaces work just fine together they aren’t visually consistent – so it’s a bit of a shift switching from one to the other during day-to-day usage. There also aren’t any migration paths from JS Link solutions to PowerApps or new custom solutions.

The future for power users, however, is really in PowerApps.

PowerApps

Get on the bandwagon now. PowerApps is the future and is a tool not just for SharePoint users – though it does bring new capabilities to SharePoint with forms and mobile accessibility. Between Power BI, Flow and PowerApps, the Business Application Platforms tools are the new area for power users to work in.

Currently, the integration between SharePoint and PowerApps is just scratching the surface, but there is more to come and in all likelihood those changes are going to be coming pretty quickly. Today you can create a PowerApp from SharePoint Online lists and the app will show up in the list view dropdown. Selecting a PowerApp today launches the PowerApps interface. While it’s not live yet, Microsoft has already demoed and shown functionality (in screenshots) of PowerApps embedded right IN a SharePoint page. Once this is possible, the user experience will be dramatically better and solutions (apps) built in PowerApps will start to replace what we previously built with separate SharePoint pages, views, and forms.

With the tools available today, PowerApps can create an app from a SharePoint list – either in O365 or on-premises if using a Gateway – and will create a form-based solution. What I hope to see is an additional template/wizard type of project that looks more like a traditional SharePoint view –hopefully even based on an existing view in more of a grid-focused solution rather than forms on a mobile-device-sized screen. We’ll see what we get. 

SharePoint Framework (SPFx)

When it comes to real customizations, the grey-area we’ve been operating in with JS Link is going away. *Real* customizations are intended to go through developers using the new SharePoint Framework (SPFx). This is managed and deployed code. Where with the current JS Link approach we could have a single JavaScript file, you now need a new stack of open source tools, projects with hundreds of files totaling over 100MB, customization of just the right files, and then deliver the finished package to an IT Pro to deploy in your environment. While this is better for the stability of the platform (again, which is good…), it is now significantly out of the reach of power users.

There’s a lot of information out there about the SharePoint Framework, but it is also new. So, we’ll be seeing changes and additions to it as it gets closer to mainstream. Bottom line is if you’re a developer in the SharePoint space, you’ll want to add SPFx to your list of things to ramp up on sooner rather than later. 

Future ‘Modern’ Interface Updates (?)

Disclaimer: This is *not* real. These concepts are a figment of my imagination and wishful thinking. There has been no word from Microsoft on any new features here.

Some of the things we’ve been doing with JS Link and CSR are relatively simple things, like column/field formatting and conditional formatting. It would be really cool if some of these ‘simple’ additions could be added to the web interface so we don’t even need to do customizations or PowerApps solutions.

What I’m thinking of is updates to how the SharePoint View is defined within the web interface. Today we have the list of columns/fields available in the list. We select the fields we want displayed in the list and set the order that the fields are displayed in.

image

A nice addition here would be to add formatting options for each column. Simplest would be simple HTML/text formatting. Next level of complexity would be conditional formatting. Next level up from that would be more along the lines of a calculated field, but combining HTML and field data like item ID. The first two at least seem reasonable to request. Smile Conditional formatting alone would likely meet the majority of requests by power users.

You certainly wouldn’t be able to do *all* the things we were doing with JS Link field and item overrides, but there are a few things that seem within reach if the SharePoint Team had them high enough on the priority list. 

Conclusion

So, choose your path. And yes, it (still) depends. Winking smile 

If you’re in an on-premises 2013 environment, you can continue using and building JS Link solutions. However, you’ll need to rebuild those solutions when you move to SharePoint 2016 or SharePoint Online. I haven’t tested migration from 2013 to 2016, but I suspect JS Link customizations would come forward as ‘Classic mode’ customizations.

If you’re in an on-premises 2016 environment, you can continue using JS Link solutions, but I would start looking at PowerApps here as well. Even with PowerApps living in the cloud, you have the ability to reach on-premises environments using Gateways. The integration likely won’t be quite as seamless as it will be in SharePoint Online, but Feature Packs may continue to improve this.

If you’re using SharePoint Online (O365), send your power users down the PowerApps path and your developers down the SharePoint Framework path. In the meantime, continue using JS Link and the pages in Classic Mode until you’re ready for the new stuff.

Previous Posts and References

JSLink – Filter on a Lookup Column with CSR

Lookup columns are both useful and a little odd in how they’re implemented in SharePoint list views. I wrote a bit about this in a previous post and showed one example on how to deal with Lookup column content. This post shows an alternative – and possibly more useful approach.

We’ll change the default link in the lookup field to a link that filters the current list by the lookup field value.  Yes, users can also use the filter built into the column header – this is just another way to implement it. I also think this is a bit more intuitive for users.

At the end of the day, this is just another example of custom link ‘building’ with CSR.
Sample File: CSR_LookupSelfFilter.js

Key lines:
image

With ‘Theme’ being the internal name of the Lookup field that we’re filtering on. Fairly straightforward.

The full list:
image

After clicking ‘Technics’:
image

Now we also need to add a ‘reset’ link to the web part so that users can get back to the default view. Otherwise, they could get stuck in a dead end after selecting a filter value. There are all kinds of ways to implement this, for simplicity’s sake we just updated the title text and link. 
Before:

image

After:
image

Obviously you don’t *actually* have to change the text of the web part header – just the URL. Smile But again, it seems like better UX.

Hope this is useful.

References:
JS Link and CSR Page

SharePoint Fest–Seattle 2016

The SPFest folks once again put on a wonderful show last week in Seattle. Big thanks to everyone involved!

Just a quick follow-up with session links to slide decks:

DEV103 – Client-Side Rendering for SharePoint: From Intro to Practical Application

  • SPFest Link
  • You can find lots of JS Link and CSR links on this page.
  • My Link
  • New post with updated script for Lookup link to filtered views (Updated: Link)

PWR202 – Designing and Building User-Friendly vs. SharePoint-User-Friendly Solutions
(previously listed as ‘DEV202’)

  • SPFest Link
  • Did you attend this session? Do you have an idea for a better title for the session?
  • My Link – Added a slide with screenshot on hiding lists with SharePoint Designer
  • Keep an eye out for new posts on PowerApps extensions to the scenario (I will add links)

I love hearing feedback so feel free to email or use the comment section. Thanks!

See you in Chicago!

The Future of SharePoint – Without(?) CSR and JS Link

Microsoft recently announced a new document library experience. Today as part of the May the 4th ‘Future of SharePoint’ event a similar new experience for lists was announced. Ultimately, good moves in the broader effort to improve user experience within SharePoint and an evolution forward. But what, if anything, does this mean for JS Link and Client-Side Rendering (CSR)?

Let’s take a look… I’m not going to give a deep tour of the new interface – that’s for another day. Just focusing on the CSR implications right now.

So, the new list and library interface is locked down. The default page still uses the default chosen view and you can quickly and easily switch views. The page, however, has no editing options. We can’t get to the edit page and edit web part interface. So no-go for CSR. Still, not terrible – while you *could* edit the default page, it wasn’t generally a good practice. (of course, there were some relevant use cases out there…)

Now, if you’re creating pages and adding web parts of these lists and libraries to the page – we’re still in the game. This hasn’t changed… yet. We can still build out pages, add CSR via JS Link and build out our solutions.

So, the short story is that CSR and JS Link still works in 2013, 2016, and O365. There are a few fuzzy spots on the radar for O365 and 2016 though. The new page experience and the new SharePoint Framework are likely to creep into the CSR space. What the roadmap details and timeline are remain to be determined.

Note: If you still need to edit the main library and list pages, you can switch back to ‘classic’ mode. This can be done at the library, site, or site collection levels. Links available below.

References and related materials:

JSLink – CSR to Override “There are no items to show in this view…”

The default message displayed in a view when that view has no items to display is:

“There are no items to show in this view of the [listname] list”.

In most cases this is just fine. When users are working directly in a list this message is consistent with the user experience.

If for whatever reason this text needs to be overridden there isn’t an obvious or simple approach to do this through the UI.

The default text is set within each list behind the scenes. If you were to change the property of the list directly using some custom approaches it would change the message for the list and be seen in all views. Using CSR, we’re going to change what is displayed without changing the core data. This give a few advantages:

  1. We generally don’t want to make permanent customizations if we don’t have to.
  2. Using CSR we can update the message for *each* view as necessary – which might be more appropriate for each use case.  

The bonus here is that it’s REALLY easy using CSR once you’ve figured it out. Smile 

So, here’s how it works:

Note: Normally I don’t add CSR to actual view pages – *especially* the All Items view – but technically you can. I generally use a separate page with a web/app part dropped on the page and apply CSR using JS Link at that point. But for this simple example we use the straight-up view page.

Our view starts out like this:

image

Now, you can take a shortcut by using the Footer override, but this will override both the default message when there are no items in the list *and* be displayed when there are items displayed. Fine if the override is blank, but not useful if you’re actually displaying a message.

overrideCtx.Templates.Footer = “ “;

The more elegant method is to override the default text in the list property SharePoint uses while leaving the logic SharePoint uses to decide when to display the message (No items in the view –> display the text). Within the list schema the property is ‘NoListItem’ and fortunately for us this property is available to us in our CSR JavaScript. In this example we use the OnPreRender override to make the change.

image

Applying this code as JS Link file gives us the following:

image

Pretty slick now that we’ve figured it out.

Thanks again to Raymond Mitchel (@iwkid) for helping with digging through the background details.