Set default value of multiple lines of text (enhanced rich text type) field in SharePoint new item forms using jQuery

A recent project tasked me with providing a default value for an enhanced rich text field. Most field types allow you to set a default value out of the box. With enhanced rich text (multi-line text field type) there’s no option to set a default value.

I decided jQuery was the route I wanted to go on this one. After Googling for a fair while I finally found a response that helped.

Modifying the answer provided there, I simplified the code that worked to:

<script src="https://sharepoint.contoso.com/SiteAssets/jquery.min.js" type="text/javascript"></script>
<script>
$(function () {
                $('div[id$="TextField_inplacerte"').text("Test");
});        
</script>

Just save that code as a .js file you upload to your site. Then reference the saved .js filepath via a Content Editor Web Part placed on the new item page (newform.aspx).

Not familiar with jQuery?

The first line of the script needs to reference jQuery. In some environments this needs to be hosted in your site (I typically use Site Assets for this). In other cases, you can just reference it hosted elsewhere (not recommended, but could work for testing/short-term in some environments). I used the code from http://code.jquery.com/jquery-latest.min.js and saved its contents as a .js file of my own that I uploaded to Site Assets. Then just replace the URL in the first line of the script with the URL of the file you uploaded to Site Assets.

More than one enhanced rich text field?

The script looks for any enhanced rich text field, and in my case I only had one in the form so it was fine. If you have more than one, just replace TextField_inplacerte with the full ID of the rich text text field on your form.

Hint: User developer tools with F12 in the browser then select the field. The ID you want will end with TextField_inplacerte and likely start with your field name.

Pass URL parameter to SharePoint new form (NewForm.aspx) to auto-populate a lookup field

I recently received a request to create an education listing of courses where a user could “Register” easily for upcoming opportunities. This required creating two lists: one for courses and another for the registrations.

The most important part of this was that when a user clicked “Register Here” on a calendar item, it would take them to this separate registration form on a completely different list and auto-populate the Training lookup drop-down based on which “Register Here” link they clicked.

Courses list (calendar app)

The first list for courses, Courses, is a calendar app with the courses. It has two necessary columns you must add:

  • A calculated column called Training: =IF([End Time]>=NOW(),(TEXT([Start Time],”YYYY-MM-DD HH:MM AM/PM”)&” | “&Title),””)
  • A custom hyperlink-type field called Register Here. The value is set by a simple SharePoint Designer workflow.

The link is structured so that when clicked, it’ll take the user to the NewForm.aspx form for the registrations list (ContinuingEdRegistration). The user will enter their info there to register for the course.

For the workflow, I used a simple two-step 2010 platform workflow for the Courses list, set to trigger on creation OR change.

When setting the variable in the workflow:

  1. Click the ellipses (three dots) to open “String builder”
  2. Paste the normal link to the second list’s NewForm.aspx page (ContinuingEdRegistration in my example)
  3. Add ?Training= to the end of it, replacing Training with whatever URL parameter you’re wanting to use to help in auto-populating a field
  4. Click “Add or change lookup” to add Current Item –> ID
  5. Add a comma and a space (will not work without space)
  6. Enter link text, like Register Here

The second (and last) step is to set the hyperlink field we created (Register Here) to that variable from the first step. Publish the workflow.

You can set the calendar view to whatever works best – an actual calendar, a list, boxed, etc. as long as the registration link is available to users to click.

ContinuingEdRegistration list (Custom list app)

The ContinuingEdRegistration list and new form is simple:

  • A lookup column to our Training on the first list
  • A field for the user being registered

The key to this working is editing this ContinuingEdRegistration’s NewForm.aspx page seen above and adding the following script via a Script Editor web part or Content Editor web part. Thanks to Emiliano Poggi for sharing the script that inspired this solution.

<script type="text/javascript">

function getUrlParameter( name )
{
name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
var regexS = "[\\?&]"+name+"=([^&#]*)";
var regex = new RegExp( regexS );
var results = regex.exec( window.location.href );
if( results == null ) return "";
else return results[1];
}
 
function populateNewForm()
{
document.getElementById("Training_67194962-c685-4033-8744-701fd9f26beb_$LookupField").value = getUrlParameter("Training");
}
_spBodyOnLoadFunctionNames.push("populateNewForm")
</script>

Be sure to update both the “ID” boxed below, as well as the URL parameter to look for (used in the SPD workflow between ? and =).

Click to enlarge

If you’re unfamiliar with getting element IDs using F12/developer tools, just go to the NewForm.aspx, hit F12, choose the “selector” probably a mouse as seen here and then left-click the element (dropdown) to get its ID. The following screenshot is using Chrome to find the ID (in blue following the # mark):

Click to enlarge

Once you’ve updated the script for your specific fields, you can either copy and paste it into a script editor web part or save the script as a .js file in a folder like Site Assets then reference it in a Content Editor web part like this:

Click to enlarge

Once you’ve pasted a link to the script in the content editor web part properties panel, click OK. Then you can stop editing/save the page to continue.

Testing

To test your solution, just modify or create a new calendar item. Here’s what should happen:

  1. Your SPD workflow runs, setting the “Register Here” hyperlink field to the correct URL with that item’s unique ID included
  2. Your user clicks that hyperlink on the calendar item and is taken to the Registration list’s NewForm.aspx page. Note that the URL should include ?Training=123 or something similar at the end- this is the URL parameter the script is looking for.
  3. The script finds the URL parameter and dynamically updates the dropdown to the lookup choice that matches the ID.
  4. The user completes the rest of the registration fields and saves/submits.

Taking it further

A further enhancement might be adding &source=CoursesListURL to the URL created in the workflow to redirect users to the calendar again after registering.

Ta-da! Best of luck.

Replace SharePoint attachment paperclip icons with actual hyperlinked attachment names in list views

You can attach documents to SharePoint list items. However if you add the “Attachments” column to your list views, you get a column that only shows a paperclip icon (see below) if there are any attachments. Clicking that paperclip also won’t open any attachment or the list item to view them. It’s strictly an image.

attachment paperclip

Here’s how you can replace that paperclip on each row with the actual name(s) of your attachment(s) linked to the actual attachment(s).

Continue reading “Replace SharePoint attachment paperclip icons with actual hyperlinked attachment names in list views”

Customize styles/formatting of SharePoint list column header rows

Note: This post applies to on-premise/server lists or O365 lists set to “classic” view. This will not work on modern views.

A little style on column header rows goes a long way. For example, just a background color and font adjustment can take your list from:

Before:

headerwithoutstyle

to
After:

headerstyle

Here’s how you can apply your own styles to your list(s).

Continue reading “Customize styles/formatting of SharePoint list column header rows”

Automatically open SharePoint 2013 workflow tasks in Edit mode for easy one-click approvals

one-click approval

On one of my recent projects, a client asked if it would be possible for the link to a task within a workflow notification email to open the task in “edit” mode instead of “display”. If you’re unfamiliar with SharePoint 2013 task processes built in SharePoint Designer, here’s what their process looked like prior to our change:

  1. Someone submits form
  2. Approval request sent to manager
  3. Manager clicks link in email to open task
  4. Manager clicks “Edit”
  5. Manager clicks “Approve”

They wanted to eliminate step 4 to make the process as easy as possible (one-click after opening link in email). Here’s what we ended up doing:

Continue reading “Automatically open SharePoint 2013 workflow tasks in Edit mode for easy one-click approvals”

How to create a SharePoint modal pop-up message on page load

2018-05-15_07-55-34

This solution involves two files:

  • The aspx page that holds the content of the pop-up
  • The script that loads the aspx page in a modal dialog upon page load
  1. Save this .aspx page to your “Site Pages” directory.
    -OR-
    Copy and paste the following into a new .aspx page in your Site Pages or Pages (Settings wheel –> Site Contents –> Site Pages or Pages) directory:

    Wrap this block in style tags:
    [code]
    h1 {
    color: #ed7522;
    text-align: center;
    }
    h2 {
    color: #ed7522;
    text-align: center;
    }
    p {
    color: #1f2844;
    font-size: 1em;
    }
    input {
    font-family: “Segoe UI”;
    font-size: 1em;
    }
    [/code]
    Paste directly beneath (no additional tags):
    [code]

    [/code]

  2. Modify the content in the aspx page beneath the modal-content div and above the input tag to include your own images, formatting and message text.
  3. Save this javascript file to your Site Assets (Settings wheel –> Site Contents –> Site Assets) or scripts folder
    -OR-
    Copy and paste the following into a new javascript file in your Site Assets:

    Note: Wrap the following in script tags:
    [code] _spBodyOnLoadFunctionNames.push(‘showPopup’);
    function showPopup() {
    var options = {
    title: “Notice“,
    url: “https://sharepointlibrarian.sharepoint.com/SitePages/HomePopUp.aspx” };
    SP.UI.ModalDialog.showModalDialog(options);
    }
    [/code]
  4. Update the script to include the URL of your newly saved aspx page and a title for the pop-up window (optional).
  5. Add a content editor web part to the page on which you’d like the pop-up.
    1. Edit page
      editpage
    2. Add web part
      insert web part
    3. Edit web part
      editwebpart
    4. Paste URL to the javascript file in your Site Assets and click “OK”
      content editor pop up
    5. Save page/stop editing
      stopediting

That’s it! Your pop-up should now function upon page load. When/if you wish to “turn off” the pop-up without deleting the files (so you can reuse later easily) just add “//” before line 7 in the javascript file and save to “comment out” the function. This prevents the pop-up from loading. When you’re ready to use the pop-up again just remove the two slashes and save.
comment out

I recommend using SharePoint Designer to easily access and modify the ASPX page and/or javascript file.

A better way to display “today’s events” from multiple calendars in SharePoint on your intranet home page

today at LMH

Below on the left are two traditional, out-of-the-box solutions for showing Today’s events in SharePoint. Notice how both take up a lot of extra space repeating today’s date (which we don’t need to see at all in a web part called “Today’s Events”) or showing gray space where there are no events. Soak that in – prime real estate on your home page goes to non-existent events. These also may require overlays and other manual labor processes that need adjusted every time a calendar is added or removed.

But on the right is what you could have. It uses search instead and displays events from all calendars a user has access to in one place. It shows only the necessary information on the home page and links to full details. And with a little CSS included in this post, it can look polished and themed. Imagine all you could do with that saved space on your home page…

Also seen above: Adding local weather to your SharePoint intranet home page
and a “this week’s menu” button for your intranet

Continue reading “A better way to display “today’s events” from multiple calendars in SharePoint on your intranet home page”

Adding local weather to your SharePoint intranet home page

Update 5/9/2019: AccuWeather has discontinued their widget. Watch
https://www.accuweather.com/en/free-weather-widgets for updates.

weatherI jokingly said at a recent presentation that I thought adding weather to our intranet’s home page was a good idea for employees like me who work in the basement and don’t see much of “the outside.” But it can also help with planning and decisions depending on your industry and daily routines.

Accuweather has a free script for a widget you can use that resizes perfectly on different screen sizes. I’m impressed with its simplicity and how dynamic it is.

All you need is a script editor where you’re placing the weather on your page and the following script from Accuweather.com. This script will work as-is from a straight copy and paste, but you should generate your own code from their website to paste after the closing style tag so that when clicked, users will be taken to more info specific to their location instead of mine. You can start from scratch on their site, just be sure to add the “style” tag and content below before the script they generate for you. This will get rid of a rather pesky button they include.

Upgrade your image slider on SharePoint

Your image slider is okay. But you’d like it better if it had a makeover (50 points to whoever can guess the commercial reference).

This post will show you how you can take your out-of-the-box content search web part slideshow from this:

2018-03-24_17-10-39

to this:

2018-03-24_17-26-46

This solution supports multi-line descriptions that don’t get cut off. It gets rid of that dreadful partially transparent overlay and gives you more of your photo uninhibited by messy design. It’s more modern, lighter and sure to impress. At the end, be sure to adjust the CSS to match your own color scheme and size needs.

Continue reading “Upgrade your image slider on SharePoint”

Show more or all views in a classic view SharePoint list

ViewCount

By default, you’ll see 3 views in a SharePoint list. Using simple javascript, we can make sure our users see that fourth or fifth view as well, reducing the number of clicks it takes for them to get to the data they need.

Continue reading “Show more or all views in a classic view SharePoint list”