When you create a list in SharePoint, there may be certain fields that you wish to hide on the list forms. One example of this is a request form. The end user fills out the form for you to process. You have some variables associated with that form, such as "status", that you don't want the end user to be able to see or change.
The code below hides form fields that are specified in the "hideFields" function. The code does not require any additional supporting classes such as jquery. This code can be put in a content editor web part on your form, or added directly to the form in SharePoint designer.
Be aware that the field names that your are going to hide are the SharePoint names for that field, not necessarily the name presented in the list. If you open your list and go to list settings, placing your pointer over the variable name will show the SharePoint name in the link:
/news/_layouts/FldEdit.aspx?List=%7B354E90D9%2D5763%2D491F%2DAA44%2DFA42D5838B4C%7D&Field=Title
This fields name is "Title" even though in the SharePoint list it is listed as "Headline".
Tips and tricks, workarounds to common issues, conventional and unconventional solutions, and philosophy...
Wednesday, June 12, 2019
Wednesday, March 13, 2019
Adding First Letter (Users Last Initial) filters to a list view web part.
Introduction
In SharePoint, you can create a diverse set of lists to hold your data, whether they be documents, service requests, or process tracking. The view tools provided by SharePoint with the various filter and grouping tools are useful for managing that data and making it easier to find a specific record.If the list grows very large those view and filter tools may not be sufficient to find the specific records you are looking for quicky and easily. In our case, we have thousands of records submitted by various users that need to be tracked. A quick way to narrow down the list is to filter that list by the users last initial. The screenshot below shows the alphabetic filter above the list, and the list it filters below it. So, clicking the "B" on the top list of links filters the list below by all users who's last name begins with B. Clicking any other letter will extract all user records that have that last initial. Clicking "Clear" clears the filter and shows all of the records in the default view set up for that page.
| List with last initial filters connected. "B" selected. |
Part One
Modify the list to extract the last letter of the field to be searched.
The first step is to extract the first letter of the field you wish to filter.
If you are using a straight text field (Single Line of Text), you can extract the first letter using a calculated column. Create a new calculated column that will hold the first letter on the list you wish to filter. Use the following formula in your field:
=LEFT([YourField],1)
where "YourField" is the column that you are extracting the first letter from.
If you want to extract from a complex field such as "Created By", you will need to use a workflow to extract that value.
As above, create a new column in your list but make it a straight text field, rather than a caluclated column.
Open SharePoint designer, and create a new list workflow named something like "Capture last initial". Ensure it is triggered whenever an item is created. Also ensure that the workflow can be manually started. This allows you to populate the new field with existing records extracted last letter.
Create two new workflow variables. One named "Captured Name" and one named "Last Initial". Both are strings.
For your first line of the workflow, choose "Action". Select "Set Workflow Variable". Choose "Captured Name" as the variable, and select the field "Current Item", "Created By", and select "Display Name" as in the screenshot below:
| Captured Name should be display name version of current item created by |
For the second line, again choose "Action", and select "Extract Substring from start of string". Choose your captured name variable as the extracted string, and choose "Copy 1 character from the start". Next, set the output variable as your last initial variable. See the workflow screenshot for more clarity. Finally, update the current items field you just created in the source list (last initial) to the value in the last initial variable:
| Completed workflow that selects last initial |
Part Two
Create the list of links to generated the URL Filter link.
First, we need a page that both hosts the list you wish to filter and the Content Editor Web Part and Query filter web part used to filter the list. Create a new web part page and add your list to be filtered to that page. Select the view that is most appropriate using the web part configuration components.
Add a content editor web part to the top of your page.
Next, we need to create some HTML that has the filter letters embedded in the URL. Here is the link format:
Create 26 of these, modifying the Initial and display letter to include each letter of the alphabet.
In your content editor webpart, insert the links you created into the following html. This will format the letter based links into something more useable, and add two "clear" boxes to remove all filters from the associated list:
Save your webpart page. You should now see something similar to the screenshot at the beginning of this article.
Part Three
Use the Query filter web part to pass link values to filter list.
The final step is getting your clicked link values passed to the list below to filter that list. This is done using a query string filter. Add a new webpart to your page and, in the "Filters" section, choose "Query String URL Filter".
Add this to your page. Click on the query string filter on your page, and choose "Edit Web Part". Leave the filter name as query string, unless you want to change it. For the query string parameter, insert the parameter we have embedded in our html described above "Initial". Click "OK".
Now, on the query string filter web part, click the drop down arrow on the right side and choose "Connections". Then choose "Send Filter Values To". Then select your embeded list on this page as your choice. If you only have one list on this page it should be your only choice.
Save your page. If you are generating your last letter with a calculated field, your filters should now work. If you are generating the last letter by workflow, then you will need to manually run the workflow for each item in your list. Its a good idea to set this up before the list gets too large, if you have that forsight. If you are generating the last letter by workflow and already have a large number of records in the list, then you can manually enter the last letter for each record using datasheet view.
Once this last letter field is populated, you should now be able to filter the list by clicking the letter links.
Monday, March 4, 2019
Create a Bootstrap enabled SharePoint Site
Introduction
This post covers the steps needed to set up a SharePoint site for the creation of web pages that support current web technologies including Bootstrap. These web pages have much more freedom in design and dynamic toolsets than the restrictions provided by the native SharePoint toolset, and it allows the creation of pages that automatically adapt to any device used.
Create Site and Add Supporting Libraries
The first step is to create a standard SharePoint site. This site can use any number of the
SharePoint site templates provided, you can select one that provides specific
tools that you need, or simply a team site to get started. A team site is used in this example.
Bootstrap uses javascript jquery files to enable specific
functionality, so first download the supporting libraries for jquery here:
Rename the jquery file you just downloaded to simply
jquery.js (extension hidden in windows).
Then add to your SharePoint sites site assets library.
Next, you need to download the resources used for Bootstrap. Navigate to the bootstrap website:
and download the latest fully tested version of Bootstrap
(not Beta or Alpha). Unzip the
file. Copy the following components from
the bootstrap folders to your site assets library (extensions may be hidden in
windows):
bootstrap.min.css
bootstrap.min.js
bootstrap.min.js
Finally, create a blank text document and title it
“style.css”. Place this document in the
site assets library as well. Your site
assets library should now look like:
Next, we create a library for our images. While we could put images in the site assets
library, an image library provides an image preview and other functionality
useful when managing multiple images.
Navigate to site contents in your SharePoint site, choose
“add an app”, and choose “Picture Library”.
Name your picture library what you wish, I called mine “Site Images”.
Create Site Page
Now that you have the supporting assets ready, you can
create your site page. Open SharePoint
Designer and open your site.
Click on your “Site Pages” library.
In the top ribbon, “New” section, choose “Page” ->
“ASPX”. Do not choose “html” as
SharePoint security will not allow it to render. Rename your page away from the default
“untitled”.
Open your new site page.
SharePoint will have included some markup by default on the page. Remove the opening and closing “form”
tags. Leave the rest. Save the page.
Link Site Page to Supporting Libraries
In your new site page, expand the “head” section. First, add links to both the bootstrap
stylesheet and your custom stylesheet.
In the head section of your new page, create the link to the
Bootstrap style sheet, as follows:
<link
rel="stylesheet" type="text/css" href="../SiteAssets/bootstrap.min.css"></link>
Repeat for the four other supporting components so that you
end up with this:
<link
rel="stylesheet" type="text/css" href="../SiteAssets/bootstrap.min.css"></link>
<link rel="stylesheet" type="text/css" href="../SiteAssets/style.css"></link>
<link rel="stylesheet" type="text/css" href="../SiteAssets/style.css"></link>
<script
type="text/javascript" src="../SiteAssets/jquery.js"></script>
<script type="text/javascript" src="../SiteAssets/bootstrap.min.js"></script>
<script type="text/javascript" src="../SiteAssets/bootstrap.min.js"></script>
Click on each of these links in SharePoint Designer. If they are configured properly, SharePoint
Designer should open the corresponding file.
Test jQuery
Next, we will insert some test script to ensure that jQuery
is loading and functioning properly. In
the head section of your new webpage, insert the following text:
<script type="text/javascript">
$(document).ready(function()
{
alert('jquery
loaded');
});
</script>
Save your page in SharePoint Designer. Navigate to your SharePoint site, and open your
new site page located in your site pages folder. If you see a alert that says ‘jquery loaded’,
then you are ready to proceed. If not,
check your links of accuracy and the format of your html page.
Create Your Page Using Bootstrap
Your page is now ready for creation using the many features
of bootstrap. If you are familiar with
the technology, proceed! If not, here is
a starting point.
Within the “body” tags, add three new sections. “Header”, “Section”, and “Footer” as follows:
<header></header>
<section></section>
<footer></footer>
Within each of these tags, add opening and closing
“container” tags as follows:
<header>
<div
class=”container”></div>
</header>
<section>
<div
class=”container”></div>
</section>
<footer>
<div
class=”container”></div>
</footer>
Next add the row tags as follows:
<header>
<div
class=”container”>
<div
class=”row”></div>
</div>
</header>
<section>
<div
class=”container”>
<div
class=”row”></div>
</div>
</section>
<footer>
<div
class=”container”>
<div
class=”row”></div>
</div>
</footer>
<header>
<div
class=”container”>
<div
class=”row”>
<div
class=”col-md-4”>
This
is four column row section.
</div>
<div
class=”col-md-8”>
This
is an 8 column row section.
</div>
</div>
</div>
</header>
Add a Bootstrap button within one of your rows using the
following syntax:
<a href="#" class="btn btn-default">Button</a>
Add an image to your site page as follows (after first
placing it in the site images library):
<img
alt="Island Health Logo" src="../Site%20Images/IslandHealthLogo.gif"></img>
If you want to add custom styles to this page, use the
style.css file created earlier and placed in the site assets library. You can access this library from directly in
SharePoint Designer, enabling easy flipping back and forth between your page
and the style sheet. Do not modify the
style css that comes with bootstrap.
You can now build out your page as you wish
using all of the features of bootstrap.
Friday, February 8, 2019
SharePoint - Building What You Want How You Want. (Using SharePoint as a web host)
SharePoint OOB
SharePoint out of the box provides a rich toolset to allow you to build a web based system with lists, document libraries, content pages and custom elements. If the project or issue you are working on fits well with the toolset, you have deep knowledge of SharePoint, and if you have a pliable client who is willing to tweak processes to work with SharePoint, then you have a fast functional solution package.However, using the out of the box components of SharePoint restricts you in both functionality and look and feel.
One of the typical starting points of new projects is a wireframe, approved by the client and ready to replicate. Trying to replicate a custom wireframe in SharePoint however can be very challenging and require changes to master pages, site layouts, and other elements to obtain a certain look and feel. And if it includes HTML5 dynamic elements and other current web technologies, out of the box SharePoint may not support it at all.
SharePoint is most efficient and powerful when you can use the out of the box components, but customization can end up taking more time than developing a system a different way.
SharePoint Development
One way to handle the challenge of needing custom functionality and appearance is to code the solution in Visual Studio and deploy the resulting package to the SharePoint farm for deployment. However, this requires a deep skill set, and an environment set up to support release of new applications through SharePoint. And for smaller projects, the time and effort is also not justified.So, for a larger scale application that is to be hosted in SharePoint, with a supportive environment, developing using code can be an acceptable way of meeting specifications.
But for smaller applications, a few custom pages, perhaps even a single page based on a precise wireframe, there is another alternative.
Using SharePoint as a Web Host
If you create a blank aspx page for SharePoint in SharePoint designer, you can put any design, any css, and text you wish on that page. You have, as with any web page, complete control of the design. You are not restricted by the appearance or functionality provided by SharePoint, you can create the page from scratch.This means you do not need a .net developer to create the custom page, you do not need the overhead of creating and deploying through the farm, you can simply create a standalone page that exactly meets your requirements.
And if you wish to add css and custom java scripts, you can add those to existing site assets libraries and simply link to them in the head of your aspx page.
Your page is still protected by the SharePoint permissions model, so you can control access as you would with any SharePoint resource.
What about functionality? If you use the SPServices jquery libraries for SharePoint, you can query and update any list that is hosted on the same site in your code. So, you can create dynamic web pages that are populated using SharePoint lists. This has the added advantage of allowing end users to modify the content using the list, without having to deal with HTML updates and approvals.
So, instead of using SharePoint's built in toolset, you instead use it more like a web host. It hosts your web pages and resources, it hosts your jquery and SP services libraries. It provides and updates dynamic data to your pages. And it is covered by the SharePoint security model. This way, particularly for smaller projects or non .net skillsets, you can achieve exactly what you need without being obstructed by SharePoints OOTB functionality.
Create a Stand Alone Web Page
- Open SharePoint Designer, open your site that you with to host the page, and select a new aspx page for that site.
- Put any css or other resources in the same sites site assets library and link to those libraries in the head section of your new web page.
- Build your page as any web page, you have complete control of look and feel. Use html5, keyframes and any other web technologies you wish. Save it and view it.
Add data source
- Download the SPServices jquery libraries and put into your site assets library.
- Add a link in the head section of your page to the jquery libraries for the two libraries needed, like this: <script type="text/javascript" src="https://..SiteAssets/jquery.SPServices-2014.02.js"></script>
- Using JavaScript and jquery, connect to your supporting lists and extract the data you wish to display on the page. As we are developing this from scratch, we are not limited to list views or other ways of displaying data, we can build the interface to whatever we wish.
SharePoint Web Page Hosting
So, if you want to be able to create a page from a wireframe, use the latest HTML5 and css tools, and have complete control over functionality, then creating stand alone pages can achieve that functionality with a standard web developer skill set. No need for the overhead of Visual Studio and application deployment, no need for a .net developer or help from the SharePoint farm team. You can independently develop and release custom web pages to support your projects as needed.Monday, June 25, 2018
Configure Visual Studio BIDS to deploy a SharePoint list report to SharePoint (SharePoint 2013)
The ability of Visual Studio Business Intelligence Services to report against a SharePoint list and create a report based on that list is a useful way of presenting data. You can then embed this report in a report viewer web part on a web part page to display. Deploying the report to SharePoint using the built in Visual Studio BIDS tools however can be tricky as it requires coordination between SharePoint site components and the report deployment configuration.
SharePoint needs to be configured in SQL Server Integrated Mode for sql server report deployment. Both of the site collection features "Report Server Integration" and "Reporting" must be enabled on the site collection level. If these are not enabled, you will not be able to create the data connection library and report library needed to support reporting.
https://your_sharepoint_site/data_connections/Forms/AllItems.aspx
Next, you will need a report library. Add a the report library app type to your site. Copy the URL of the report library again removing the trailing information:
https://your_sharepoint_site/reports/Forms/current.aspx
Click the OK button once finished. Right click the project name and choose "Deploy". You will see the progress in the output window of your deployment. Now, navigate to your report library, click on the name of the report, and verify it is working. You can directly use this link on other pages in your site to refer users to this report.
Your reports will not be viewable by other non site admins until it is "Published". Once you have the report deployed and approved by your client (if necessary), navigate to the report library, click the three dots to the right of the report name and choose "Publish a major version". This will make your report viewable by all users who have permissions to your site.
Sometimes you will want to host the report in a webpart page, rather than have the report open directly. To do this, create a new web part page in SharePoint and insert the "SQL Server Reporting Services Report Viewer" located in the "SQL Server Reporting" category. Use the report viewer web part tools to select and embed your report.
Optionally, you can enable remote errors for reports in local mode using the "Site Settings->Reporting Services->Reporting Services Site Settings" site action. Put a checkmark in the box "Enable remote errors in local mode". This will give you a more detailed error message if your report fails.
SharePoint needs to be configured in SQL Server Integrated Mode for sql server report deployment. Both of the site collection features "Report Server Integration" and "Reporting" must be enabled on the site collection level. If these are not enabled, you will not be able to create the data connection library and report library needed to support reporting.
Step 1 - Create the report
Open Visual Studio BIDS and create a new report project. Create a new Shared Data Source that extracts data from the SharePoint list you wish to work on. Create a new dataset based on that datasource to pull out the fields you wish from that list. Develop your report locally using Visual Studio and its "preview" feature to complete and test the report.Step 2 - Set up the SharePoint site repositories
The first component you will need to add is a data connection library. Add this list type to your SharePoint site. Navigate to this library and copy the url. Remove any trailing data after the list name(in bold):https://your_sharepoint_site/data_connections/Forms/AllItems.aspx
Next, you will need a report library. Add a the report library app type to your site. Copy the URL of the report library again removing the trailing information:
https://your_sharepoint_site/reports/Forms/current.aspx
Step 3 - Configure Visual Studio Deployment and Deploy
Within Visual Studio, right click on the name of your report. Select "properties". This will bring up the Configuration manager for your report project. Here are the configuration properties required to deploy the report to SharePoint:| Overwrite Datasets | True |
| Overwrite Data Sources | True |
| Target Dataset Folder: | https://your_sharepoint_site/data_connections |
| Target Data Source Folder: | https://your_sharepoint_site/data_connections |
| Target Report Folder | https://your_sharepoint_site/reports |
| Target Report Part Folder: | |
| TargetServerURL: | https://your_sharepoint_site |
| Target Server Version: | SQL Server 2008 R2 or later |
Click the OK button once finished. Right click the project name and choose "Deploy". You will see the progress in the output window of your deployment. Now, navigate to your report library, click on the name of the report, and verify it is working. You can directly use this link on other pages in your site to refer users to this report.
Tricks and Tips
You will sometimes get a permissions error if you deploy a report to SharePoint if you did not specify credentials for the data source. Ensure that your data source has "Use Windows Authentication" selected within the data source properties.Your reports will not be viewable by other non site admins until it is "Published". Once you have the report deployed and approved by your client (if necessary), navigate to the report library, click the three dots to the right of the report name and choose "Publish a major version". This will make your report viewable by all users who have permissions to your site.
Sometimes you will want to host the report in a webpart page, rather than have the report open directly. To do this, create a new web part page in SharePoint and insert the "SQL Server Reporting Services Report Viewer" located in the "SQL Server Reporting" category. Use the report viewer web part tools to select and embed your report.
Optionally, you can enable remote errors for reports in local mode using the "Site Settings->Reporting Services->Reporting Services Site Settings" site action. Put a checkmark in the box "Enable remote errors in local mode". This will give you a more detailed error message if your report fails.
Wednesday, June 13, 2018
Create a dynamic content slider against a SharePoint list using jQuery. SharePoint 2007, 2010, 2013
On the front page of many SharePoint sites there is a section called "news" or "announcements". Located on the home page of your company or organization site, this is a quick way to disseminate important information to all users of your SharePoint site.
This is usually set up using a SharePoint list that contains the announcements or news items, and a content query web part on the front page gets the most recently published news item or article. This is a quick way to update the home page without having to edit the html source on that page every time the news or announcement changes.
However, the issue with this approach is that it only shows one announcement at a time. Sometimes, there may be multiple news items or announcements to show on the home page, but you don't have the space on the page for multiple items.
I was tasked with taking an existing news content query web part and replacing it with a Content Slider. This would show each news item on the page for a few seconds, and then scroll to the right for the next news item. A group of buttons at the bottom allows direct control of which news item you wish to see.
This is a fairly standard way of presenting information on the web, and so there are a lot of javascript and css based solutions for this challenge available. However, I wanted to host this solution in SharePoint 2007, and wanted to be able to use jQuery to extract information from the SharePoint news list. So it made sense to look into a few of the available jQuery content sliders to see which would meet my needs. The final choice ended up being awShowcase, you can download it from here:
Awkward Showcase on GitHub
Download and unzip the AWShowcase files locally, and place the unzipped files and folders in your site assets library. Download the jquery source file and SP Services jquery source files and place those in your site assets library as well. Your site assets library should look similar to this:
You may already have a start date associated with your announcement/news list. If not, add it now. If you name it "StartDate" as one word, then you won't need to change the jquery for that field later.
You will also have a field that contains the announcement content. In my case, I called the field "HTML" because it allows rich html content to give richer tools to people entering the slider content. You will need to change the field name in the code below if it is not "HTML".
If you have not already enabled it, enable approval for the announcments/news list. The list items must be approved to show on the content slider.
Add links to your supporting libraries at the top of your html content:
Now, copy and paste the following code underneath your supporting library links:
The other potential source of issues is within the field names. Be sure your field names are the internal SharePoint names for those items, rather than the name displayed on the list. If you are unsure what the internal name is, open properties for that list, and hover over the column names. The link that appears will contain the actual field name at the end.
The field looks like "Start Date" but when we hover over the field we see this URL
/_layouts/FldEdit.aspx?List=%7B06826D90%2D478A%2D423F%2DA762%2DDFCDD7005964%7D&Field=StartDate
we know the actual field name is "StartDate".
This is usually set up using a SharePoint list that contains the announcements or news items, and a content query web part on the front page gets the most recently published news item or article. This is a quick way to update the home page without having to edit the html source on that page every time the news or announcement changes.
However, the issue with this approach is that it only shows one announcement at a time. Sometimes, there may be multiple news items or announcements to show on the home page, but you don't have the space on the page for multiple items.
I was tasked with taking an existing news content query web part and replacing it with a Content Slider. This would show each news item on the page for a few seconds, and then scroll to the right for the next news item. A group of buttons at the bottom allows direct control of which news item you wish to see.
This is a fairly standard way of presenting information on the web, and so there are a lot of javascript and css based solutions for this challenge available. However, I wanted to host this solution in SharePoint 2007, and wanted to be able to use jQuery to extract information from the SharePoint news list. So it made sense to look into a few of the available jQuery content sliders to see which would meet my needs. The final choice ended up being awShowcase, you can download it from here:
Awkward Showcase on GitHub
Step 1: Download supporting libraries.
Within the SharePoint site that is going to be hosting your content slider, locate your site assets library. If it doesn't exist, create a document library called site assets.Download and unzip the AWShowcase files locally, and place the unzipped files and folders in your site assets library. Download the jquery source file and SP Services jquery source files and place those in your site assets library as well. Your site assets library should look similar to this:
Step 2: Update your news or announcements library.
If you have an existing news or announcements list, you will need to add and update a couple of fields to make it work with this content slider. The first thing to add is a field called "Slider". This is a straight text field. If you want your announcement or news article to appear in the slider, you put the letter "Y" in this textbox.You may already have a start date associated with your announcement/news list. If not, add it now. If you name it "StartDate" as one word, then you won't need to change the jquery for that field later.
You will also have a field that contains the announcement content. In my case, I called the field "HTML" because it allows rich html content to give richer tools to people entering the slider content. You will need to change the field name in the code below if it is not "HTML".
If you have not already enabled it, enable approval for the announcments/news list. The list items must be approved to show on the content slider.
Step 3: Add and populate the content editor web part.
Navigate to the page you wish to display the new content slider on and edit the web part page. Add a new content editor web part. Edit this web part and choose to edit the HTML source.Add links to your supporting libraries at the top of your html content:
Now, copy and paste the following code underneath your supporting library links:
Step 4 - Modify the code to suit your environment.
Make the following changes in the code:- Update all of the view fields in the CAML query to match your field names. So if the field I call "HTML" is called "Announcement" in your source list, change all instances of HTML to "Announcement". Make sure you change the names in all locations, use search and replace.
- Update the name of the announcements list to match the name of your source list. In the code above, our list is called "spotlight".
- Refer to the github link at the beginning of this article to understand the showcase property customizations. You will want to modify the width and height to fit your page.
The other potential source of issues is within the field names. Be sure your field names are the internal SharePoint names for those items, rather than the name displayed on the list. If you are unsure what the internal name is, open properties for that list, and hover over the column names. The link that appears will contain the actual field name at the end.
The field looks like "Start Date" but when we hover over the field we see this URL
/_layouts/FldEdit.aspx?List=%7B06826D90%2D478A%2D423F%2DA762%2DDFCDD7005964%7D&Field=StartDate
we know the actual field name is "StartDate".
Friday, June 8, 2018
Using callbacks to force function completion in order (jQuery)
I had a recent issue with a dynamic page constructed in SharePoint using jQuery. The page had two functions. The first used SPServices to extract data from a SharePoint list. The second configured the jQuery ShowCase object to create a content slider based on the content extracted from the SharePoint list. However, while the content initially loaded, any button or link clink would clear the content, the ShowCase went blank.
I put some alerts into the code to find out what was happening and found that, if I had an alert at the end of each function, they worked. If I removed the alerts, it no longer worked.
What was happening here was that the alerts were giving enough time for one function to complete before the other started. The first function would fire, the alert would come up on the screen. This would give sufficient time for the data to return and then the ShowCase Function would fire on the completed content. But how to do this without alerts?
The answer was jQuery callbacks. This code forces the execution of each function in sequence, and, critically, does not fire the second function before the first has completed. Here is what that looks like:
var callbacks = $.Callbacks(); // create callbacks object
callbacks.add(getData); // add the data extraction function
callbacks.add(renderShowCase); // add the ShowCase render function
callbacks.fire(); // fire those functions in sequence.
By default, javascript functions on a page load to not complete (and return data) before subsequent functions are fired. If none of the functions are dependent on others completing, then this is the most efficient way of rendering the page. If however one of the functions is dependent on another completing before firing, callbacks are an excellent solution.
I put some alerts into the code to find out what was happening and found that, if I had an alert at the end of each function, they worked. If I removed the alerts, it no longer worked.
What was happening here was that the alerts were giving enough time for one function to complete before the other started. The first function would fire, the alert would come up on the screen. This would give sufficient time for the data to return and then the ShowCase Function would fire on the completed content. But how to do this without alerts?
The answer was jQuery callbacks. This code forces the execution of each function in sequence, and, critically, does not fire the second function before the first has completed. Here is what that looks like:
var callbacks = $.Callbacks(); // create callbacks object
callbacks.add(getData); // add the data extraction function
callbacks.add(renderShowCase); // add the ShowCase render function
callbacks.fire(); // fire those functions in sequence.
By default, javascript functions on a page load to not complete (and return data) before subsequent functions are fired. If none of the functions are dependent on others completing, then this is the most efficient way of rendering the page. If however one of the functions is dependent on another completing before firing, callbacks are an excellent solution.
Wednesday, April 11, 2018
Two key roles for any technical project
Learning the Hard Way
As may readers of this blog have undoubtedly found, there are many challenges facing technical teams and project managers having to deliver technical solutions within a known period of time. Many of these challenges can result in deadlines missed, budgets blown, and, in the worst case, the project abandoned.2. Project Technical Lead
Primary Client Stakeholder
A primary client stakeholder is the person who is the main point of contact for the project technical lead. They provide information about the current system processes and inform the development of the new system. The client stakeholder should have three key attributes.- Deep understanding of current system/process being replaced.
- Enthusiastic availability for questions and meetings.
- Understands why current system/process is being replaced and is highly motivated to ensure that replacement is successful.
Project Technical Lead
It continues to surprise me when technical projects fall behind, and even fail, based on technical knowledge. Whether your project is internally resourced, or you are hiring an external company, the Project Technical Lead for the technical team is critical to the projects success.It seems that some service providers in the IT business are able to obtain projects in areas they are simply not qualified due to a successful sales team or a personable executive. And then the company struggles to complete the project, expectations are rolled back, and, if your lucky, you end up with a portion of what you had originally planned for.
- Has completed and delivered multiple projects in this .
- Is available for the duration of the project (even if it goes long).
So, while having a company experienced delivering project of this type in your technology is a great start, you also need to ensure that the technical lead on that team ALSO has that level of experience.
And internally, having a team that has already delivered this type of project before is a much easier path to success than most others. Whether internally or externally delivered, the core technical success on a project is primarily determined by the second key role, the Project Technical Lead.
And internally, having a team that has already delivered this type of project before is a much easier path to success than most others. Whether internally or externally delivered, the core technical success on a project is primarily determined by the second key role, the Project Technical Lead.
No Shortcuts
It can be tempting to try and shortcut past these two key roles and not spend the time necessary to ensure that the experience, commitment and availability of resources is in place before starting. However, time spent here will result in a much higher likelihood of success. Learn the lessons of the past and apply them to ensure success in the future.Wednesday, October 4, 2017
SharePoint 2013 Simple Document Sign Off (adapatable to SharePoint 2010)
What is it?
Simple document sign off is a series of SharePoint customizations that allow end users to sign off on documents that they have reviewed to allow formal tracking of document review. SharePoint allows approvals of documents from draft to a published state, but it does not natively allow sign off for end users on published documents.There are many documents that may require a review and tracked sign off after they have been created or updated, including but not limited to:
- Employee Benefits
- Medical Testing Procedure Documents
- Key Business Procedures
- Contract Changes
- Equipment Usage Procedures
- Equipment Maintenance Procedures
- Emergency Protocols
- Changes to Invoicing Processes
How does it work?
The document owner adds or updates a document in a document library. They then add in the users or group they want to notify that the document has been updated to the document properties, and click the "notify" button:The end users then receive an email that gives them information about the document, a link to the document, and a link to the sign off page:
After reviewing the document the end user clicks the link to the sign off page and sees this:
After the user has registered their sign off, they can then review all of their sign off in the system:
Multiple user sign offs can be managed by the document owner in a central area. Who signed off on the document, the version signed off on, the date they signed off and the document name are all captured:
Multiple versions are managed through workflows configured in this system.
Wednesday, June 28, 2017
Display the current users Profile Image in SharePoint using EWS.
Introduction
If your IT department has configured it, you can retrieve the thumbnail images used in Outlook from the Exchange Server for your own purposes. This can be useful for customizing the look of various sites in SharePoint, such as employee dashboards.This post describes how to retrieve and use the image, and how to handle the condition where the users email does not resolve to an image.
Retrieve the Image using EWS
The image is retrieved by using a URL of the following format:https://Exchange Server/ews/Exchange.asmx/s/GetUserPhoto?email=email address&size=size code
Exchange Server = server that hosts exchange, URL provided by IT
email address = email of the user you are retrieving the image for
size = HR48x48 | HR64x64 | HR96X96 | HR120X120 | HR240X240 | HR360X360 | HR432X432 | HR504X504 | HR648X648
A sample url that would resolve to the user "Ian.mctavish@yourplace.ca" with a 64 x 64 thumbnail would be:
https://Exchange Server/ews/Exchange.asmx/s/GetUserPhoto?email=Ian.mctavish@yourplace.ca&size=HR64x64
Interesting, but how would we use this?
Using the Image on a Page
In its simplest state, you could include this as the url for an image and have it render on any page:<img alt="Profile Image" src="https://Exchange Server/ews/Exchange.asmx/s/GetUserPhoto?email=Ian.mctavish@yourplace.ca&size=HR64x64" />
This is great for displaying a specific user image on a page, but what if you want to display the current users image instead?
Displaying the Current Users Image
Download and reference JQuery
We can include the jQuery javascript libraries on our page, and use a couple of those functions to extract the image and set the value of the image on page load. You will first need to configure your SharePoint webpage to include the jQuery libraries by first downloading the libraries to your site assets folder, then referencing those libraries within your page:<script type="text/javascript" src="/SiteAssets/jquery-1.11.3.js"></script>
<script type="text/javascript" src="/SiteAssets/jquery.SPServices-2014.02.js"></script>
Create Default Image
One of the things we need to anticipate is users who's email addresses do not resolve to images. We certainly don't want the dreaded "X" to appear when an image cannot be found. So we handle this by creating a generic profile image for all users and storing it within the SharePoint site. We will configure the page to first display this image, and then, if a profile image is found, then replace it with this image.Set up the generic image (notice ID value) and put it on your SharePoint page:
<div id="UserImage"><img class="ihss-user-image" src="/Images/user.png" alt=""/></div>
This will resolve when the page loads to your generic user image.
Retrieve the Profile Image
Create a script section on your page and enter the following code:$(document).ready(function() {
SetProfileImage();
});
function SetProfileImage()
{
var thisUserEmail = $().SPServices.SPGetCurrentUser({
fieldName: "Email",
debug: false
});
var profileImagePath = 'https://exchange.yourweb.ca/ews/exchange.asmx/s/GetUserPhoto?email=' + thisUserEmail + '&size=HR120x120';
var img = new Image();
img.onload = function() {
//alert('image source: ' + img.src);
//alert('image height: ' + img.height);
var divHTML = "<img class=\"ihss-user-image\" src=\"" + profileImagePath + "\" />";
//alert('image html: ' + divHTML);
$('#UserImage').html(divHTML);
}
img.src = profileImagePath;
}
The code functions as follows:
1. Once page has finished loading call set profile image
2. Retrieve current users email using SPServices.SPGetCurrentUser
3. Generate Exchange Server URL using email address
4. Configure onload function to update image to resolved profile path if found.
Leveraging the EWS to return user profile images is one way to display the current users Profile Image in SharePoint. The approach used here ensures that, if the user doesn't have an image, or the server is not responding, then the default profile image will be displayed instead.
Thursday, June 15, 2017
Expand the first group only on a SharePoint List View Web Part (SharePoint 2013)
If you add as SharePoint list view web part to a SharePoint page using SharePoint designer, you are given the ability to sort, group and filter the results of that web part for display. If you choose to group by a specific element, then you can decide to either expand or contract all groups by default. Handy.
However, if you want to expand just the first grouping, and have the rest of the groups collapsed, there is no default setting to allow that to occur. I have taken the original blog post posted here:
Original Blog Post
and have updated it for SharePoint 2013.
The original idea used here is sound, locate and click, using javascript and jquery, the plus sign located next to the first group. However, using the web part ID did not work in my case, so I had to dig a bit deeper.
Here is the code I used to call the function:
<script type="text/javascript">
$(document).ready(function() {
collapseGroups();
});
And here is the slightly modified function:
function collapseGroups() {
var closestElement = document.getElementById('group0');
var myimg = closestElement.getElementsByTagName('img')[0];
var mysrc = myimg.src;
$(myimg).parent().click();
}
</script>
The challenging part of getting this working is identifying the document element that is closest to the + sign. The original post used the name of the web part that hosts the list data, however, this did not work in my case. Instead, it clicked the first columns sort header in the web part, and resorted the list by that column on page load!
So the approach is fine, click the + sign once you find it, we just need to find an element deeper in the list view web part. Here is how I did it.
Navigate to your web part page and make note of the Group Header for your grouped column. So if you were grouping by "Course Year", then "Course Year" would be what you are looking for.
Open the page in source view, and search for your grouping column name. When I searched for "Course Year" I got back html that looked like this:
<tr id="group0">
<td colspan="100" nowrap class="ms-gb">
<a href="javascript:" onclick="javascript:ExpCollGroup('0-1_', 'img_0-1_',event, true);return false;">
<img src="/_layouts/15/images/plus.gif" border="0" alt="expand" id="img_0-1_"> Course Year</a>
You can see the plus image markup, plus javascript event associated with that markup that fires the button clicked event. Unfortunately, between page refreshes, the image id changes, so I couldn't use that.
However, the closest element with an ID was the table row (tr) that wrapped this line. This tr has an ID of "group0". I used this ID value in the collapse groups function, and it worked! And it appears to be a more stable name than the ever changing values of the + image.
However, if you want to expand just the first grouping, and have the rest of the groups collapsed, there is no default setting to allow that to occur. I have taken the original blog post posted here:
Original Blog Post
and have updated it for SharePoint 2013.
The original idea used here is sound, locate and click, using javascript and jquery, the plus sign located next to the first group. However, using the web part ID did not work in my case, so I had to dig a bit deeper.
Here is the code I used to call the function:
<script type="text/javascript">
$(document).ready(function() {
collapseGroups();
});
And here is the slightly modified function:
function collapseGroups() {
var closestElement = document.getElementById('group0');
var myimg = closestElement.getElementsByTagName('img')[0];
var mysrc = myimg.src;
$(myimg).parent().click();
}
</script>
The challenging part of getting this working is identifying the document element that is closest to the + sign. The original post used the name of the web part that hosts the list data, however, this did not work in my case. Instead, it clicked the first columns sort header in the web part, and resorted the list by that column on page load!
So the approach is fine, click the + sign once you find it, we just need to find an element deeper in the list view web part. Here is how I did it.
Navigate to your web part page and make note of the Group Header for your grouped column. So if you were grouping by "Course Year", then "Course Year" would be what you are looking for.
Open the page in source view, and search for your grouping column name. When I searched for "Course Year" I got back html that looked like this:
<tr id="group0">
<td colspan="100" nowrap class="ms-gb">
<a href="javascript:" onclick="javascript:ExpCollGroup('0-1_', 'img_0-1_',event, true);return false;">
<img src="/_layouts/15/images/plus.gif" border="0" alt="expand" id="img_0-1_"> Course Year</a>
You can see the plus image markup, plus javascript event associated with that markup that fires the button clicked event. Unfortunately, between page refreshes, the image id changes, so I couldn't use that.
However, the closest element with an ID was the table row (tr) that wrapped this line. This tr has an ID of "group0". I used this ID value in the collapse groups function, and it worked! And it appears to be a more stable name than the ever changing values of the + image.
Wednesday, March 22, 2017
Using SharePoint list images in Jquery getListItems
If you use JQuery's getListItems function to return an image from a SharePoint list, you will typically do something like this;
$().SPServices({
operation: "GetListItems",
async: false,
listName: "leadsSelfContent",
CAMLViewFields: "<ViewFields>
<FieldRef Name='WebOptimizedImage' />
...
</ViewFields>",
CAMLQuery: "<Query>
...
</Query>",
completefunc: function (xData, Status) {
$(xData.responseXML).SPFilterNode("z:row").each(function() {
var ListItemImage = $(this).attr("ows_WebOptimizedImage"); ....
This is standard JQuery get list items format. However, what happens when you want to use that value? You cannot set an image field directly to this value as it will not work.
Since SharePoint actually returns two values for the image, one being the URL, one being the description, we only want the URL. So we need to extract it from the result returned from JQuery by using the following:
ListItemImage = $(this).attr("ows_WebOptimized").split(",")[0];
This extracts the URL, which we can then apply to our html field:
$("#PageImage").attr({src : ListItemImage});
Effecting this field in HTML:
<img class="main-picure" src="" id="PageImage"></img>
This works. However, if we don't have an image in the associated list from SharePoint, then the entire script fails. Why? Because this line will throw an error when the field being returned is undefined:
ListItemImage = $(this).attr("ows_WebOptimized").split(",")[0];
So, we first need to test to see if a result has been returned for this field before returning, and capture the undefined value, as follows:
if(typeof(ListItemImage ) === 'undefined')
{
ListItemImage = "Empty";
}
else
{
ListItemImage = $(this).attr("ows_WebOptimized").split(",")[0];
}
Finally we test for the result before setting the html field:
if(ListItemAllLeadersimageField != "Empty")
{
$("#PageImage").attr({src :ListItemImage });
}
This way, if the field is empty, our script will still run.
The code in its entirety looks like this:
$().SPServices({
operation: "GetListItems",
async: false,
listName: "leadsSelfContent",
CAMLViewFields: "<ViewFields>
<FieldRef Name='WebOptimizedImage' />
...
</ViewFields>",
CAMLQuery: "<Query>
...
</Query>",
completefunc: function (xData, Status) {
$(xData.responseXML).SPFilterNode("z:row").each(function() {
var ListItemImage = $(this).attr("ows_WebOptimizedImage");
if(typeof(ListItemImage ) === 'undefined')
{
ListItemImage = "Empty";
}
else
{
ListItemImage = $(this).attr("ows_WebOptimized").split(",")[0];
} if(ListItemAllLeadersimageField != "Empty")
{
$("#PageImage").attr({src :ListItemImage });
}
This code will allow you to extract an image from a SharePoint list, test for an empty result, and then extract the URL from that result if not empty to set an html field.
$().SPServices({
operation: "GetListItems",
async: false,
listName: "leadsSelfContent",
CAMLViewFields: "<ViewFields>
<FieldRef Name='WebOptimizedImage' />
...
</ViewFields>",
CAMLQuery: "<Query>
...
</Query>",
completefunc: function (xData, Status) {
$(xData.responseXML).SPFilterNode("z:row").each(function() {
var ListItemImage = $(this).attr("ows_WebOptimizedImage"); ....
This is standard JQuery get list items format. However, what happens when you want to use that value? You cannot set an image field directly to this value as it will not work.
Since SharePoint actually returns two values for the image, one being the URL, one being the description, we only want the URL. So we need to extract it from the result returned from JQuery by using the following:
ListItemImage = $(this).attr("ows_WebOptimized").split(",")[0];
This extracts the URL, which we can then apply to our html field:
$("#PageImage").attr({src : ListItemImage});
Effecting this field in HTML:
<img class="main-picure" src="" id="PageImage"></img>
This works. However, if we don't have an image in the associated list from SharePoint, then the entire script fails. Why? Because this line will throw an error when the field being returned is undefined:
ListItemImage = $(this).attr("ows_WebOptimized").split(",")[0];
So, we first need to test to see if a result has been returned for this field before returning, and capture the undefined value, as follows:
if(typeof(ListItemImage ) === 'undefined')
{
ListItemImage = "Empty";
}
else
{
ListItemImage = $(this).attr("ows_WebOptimized").split(",")[0];
}
Finally we test for the result before setting the html field:
if(ListItemAllLeadersimageField != "Empty")
{
$("#PageImage").attr({src :ListItemImage });
}
This way, if the field is empty, our script will still run.
The code in its entirety looks like this:
$().SPServices({
operation: "GetListItems",
async: false,
listName: "leadsSelfContent",
CAMLViewFields: "<ViewFields>
<FieldRef Name='WebOptimizedImage' />
...
</ViewFields>",
CAMLQuery: "<Query>
...
</Query>",
completefunc: function (xData, Status) {
$(xData.responseXML).SPFilterNode("z:row").each(function() {
var ListItemImage = $(this).attr("ows_WebOptimizedImage");
if(typeof(ListItemImage ) === 'undefined')
{
ListItemImage = "Empty";
}
else
{
ListItemImage = $(this).attr("ows_WebOptimized").split(",")[0];
} if(ListItemAllLeadersimageField != "Empty")
{
$("#PageImage").attr({src :ListItemImage });
}
This code will allow you to extract an image from a SharePoint list, test for an empty result, and then extract the URL from that result if not empty to set an html field.
Friday, March 17, 2017
Using SharePoint Picture Library thumbnail and web optimized images in other lists
Introduction
The post previous to this showed how to expose the thumbnail and web optimized images hidden from most users in a SharePoint Picture Library.
You could then use these images however you wish, to provide thumbnail views, use those thumbnails on pages, use the web optimized images wherever you would have used the original larger image, etc...
What if we want to take this to the next level? What if we want to include these images in other lists so that users can select them, and we automatically have the web optimized and thumbnail versions there as well?
If you add an image field to a SharePoint list, end users are expected to know how to add an image to a separate list repository, copy the URL of that picture, and paste it into the correct fields:
This process is a bit tougher than simply changing text or selecting an image. What if we could also simplify the way users update the image?
So our goals here are:
1. Simplify user image selection process.
2. Make available thumbnail and web versions.
An Example
If we have a list that is "company announcements", where, every week, an new announcement and image is added, and this information is displayed as web part on the front page of the site. This is a very simple implementation of SharePoint functionality, but it does run into two main challenges:
1. End users find the copying and pasting of an image url into an image field a more complex and error prone task.
2. End users sometimes add huge images to SharePoint, not knowing how to optimize them.
Also, if you have a list with image fields, views on that list that expose the field can be awkward and difficult to manage. Replacing the image fields with the thumbnail versions makes the views appear much more manageable:
If we can simplify the way users select existing images in a list, and expose web optimized and thumbnail versions of those images, we can improve the user experience and leverage the optimized images for our own purposes.
Steps:
1. Create a picture library with the thumbnail and web optimized image paths exposed. This is described in the prior post. For our purposes, the title field needs to be populated. The simplest way to do this is make the title field mandatory, so that users adding the picture must add a title. Or, you can create workflow that copies the picture name to the title whenever a new item is created. Whichever works best for you.
3. Create three new fields in your destination list. They are Thumbnail (type picture), Web Optimized (type picture), and 'Prior Image Thumbnail Name' (type single line of text).4. Open SharePoint designer and create a new workflow against your destination list. Set this workflow to run automatically whenever an item is created or changed.
5. Create two workflow variables, ThumbNailURL, and WebImageURL, both type string.
6. Create a condition on your workflow to only run if an image is added to the list:
7. Populate the local workflow variables with the lookup values extracted from the source list:
8. Extract just the URL from the lookup values as they have additional text prepended to the front using the 'Extract Substring from Index of String' action:
9. We only want to run this workflow if the picture has been updated. So we test to see if the 'Prior Image Thumbnail Name' has been changed to detect this condition:
10. Now we set both of the image type path values, and we set the thumbnail name for testing against as in step 9:
11. The entire workflow should look like this:
Save and publish this workflow. After ensuring the image exists in the picture library, add the picture using the title lookup on your destination list. This workflow should autopopulate both the thumbnail and web optimized image fields for your usage.
Conclusion
You can now expose those images for your own usage from the list, such as thumbnails for views, or using in web parts on other pages.
In our company announcement example, we now have a simpler way for users to select an image once they have added it to the picture library (drop down instead of copying and pasting url), and we have the two additional image types generated. The web optimized version would be used on the company announcement web part on the home page, rather than the image uploaded by the user. This will not only make the page more efficient, but can take care of styling issues caused by importing huge images.