In this post, I will show you, the non-developers how to use JS Link, and some extreme basics about how it works. Once you are armed with this knowledge and you want to research it further, you will better be able to translate what the developers are writing and maybe be able to use it.
Here we go, and remember that I am not a programmer and I don’t know anything technical, I’m just figuring it out as I go. This blog post was my inspiration.
Okay, I’m going to use a super simple example here, because mostly what I’m demonstrating is not the script language and how to program, but how to get JSLink actually working in your environment. Again, this is really cool to me, because it allows us to do conditional formatting in views and forms without the need for SharePoint Designer or InfoPath! The example is a SharePoint list of patients in a hospital. There is a column called “Progress Level”, and their level is either “Good” or “Bad”. Very simple. I want to show the good ones with green text and the bad ones in red. Actually, in order to demonstrate an image in conditional formatting versus a text color, the good ones will show in green text, and the bad ones will show a red icon, like this:
So here are the steps to do this:
- Create a custom list with a choice column in it called Progress. Make the two choice options Good and Bad. When you create this column, make sure you call it Progress, and you’re not just renaming some other column and calling it that. This is important to making it work correctly.
- Insert this new list on your homepage or some page on your SharePoint site, as a web part, and make sure the Progress column is showing.
- Download this file to your computer. It’s just a text file, but you’ll need to save it as a .JS file. See, I removed the .TXT and changed the Save as type to All Files.
- If you have access to the root level of your site collection, go there and go to Site Settings. In the Web Designer Galleries section, click Master Pages. Then click the Display Templates folder.
- Here is what you are prompted with, and what to fill in, and click SAVE.
- Here are what some of the settings mean:
Target Control Type:
View – a view in a list of multiple items
Form – a form that users are filling out, such as dispform/editform/newform.
Field – just a single field, although I can’t find any references that really explain what this one is for and when it would be used.
Standalone: Every reference I’ve seen says to set this to Override, but no one says what the purpose of the other option (Standalone) would be.
Target Scope: This is the URL relative to the site collection. So here I put a / because I want this JS file to be available to use anywhere in the site collection. If I only wanted to be able to use this code on a sub-site called “IT”, I would type /IT in this box.
Target List Template ID: The list in my example is a custom list (see step 1), and the code for a custom list is 100. Here is a list of a bunch of other codes for the other list types. Scroll down to the section called Type, to see the long list of codes. I know it says 2010, but I can’t seem to find a list of updated codes for the latest version. There are only one or two new list types in 2013, and the rest are going to be the same.
If you’ve got your file uploaded now, you can skip to step 12.
- Go to step 6.
- Anyway, now that your JS file has been uploaded, you’ll need the URL to it. In the Files tab of the ribbon, click the View Properties button for this JS file you just uploaded. Right click on the name of the file and click Copy Shortcut.
- Now that you have the URL to the JS file, remember that web part from step two? Go to that web part in the browser, and open the web part properties toolpane. Expand the Miscellaneous section (more on that in my other post). Paste your URL in the JS Link box. Notice that when you save the web part, nothing magical happens. Go back into the web part properties and notice that the URL is now showing as relative, like since my library is “Test”, it changed the URL to /Test/PatientList.js
You need to put the ~site at the beginning, as shown here. If your JS file were being stored in a library at the root of your site collection, and you were referencing it from web parts in sub-sites, you would use ~sitecollection instead.
Now, save your page, and your web part looks like that that first screenshot (at least the progress column does). At step two, I instructed you to put your list on a page as a web part, but if you want to you can just go to any regular view of your list, click the (Settings) gear at the top right and click Edit Page. From there you can do step 13.
Wes Preston has a great blog, with a lot of posts about JS Link, and here’s a great “primer” that he wrote about it. There are also hundreds of other blog posts out there about JS Link.
I’ll get into dissecting the syntax in another post. In the meantime, feel free to dig in and see how the conditional formatting works, and browse the plethora of posts about it.
In SharePoint 2013 and Office 365, there are a couple of pretty useful new web part properties that I would like to point out. When inserting an “app part” on a page (a list or library web part), there is a Miscellaneous section in the web part property toolpane.
- Insert a list or library (app) as a web part on a page in SharePoint.
- Open the web part properties toolpane. (Select the web part and in the ribbon on the Web Part tab, click Web Part Properties)
- Expand the section called Miscellaneous.
Disable view selector menu
This option is checked by default. When unchecked, will show the names of the views in the web part. When you click on the name of a view, it will navigate you over to that list or library. So, even though you’re not staying within the context of whatever web part page you’re on, at least it will get you to another view of the list/library.
Disable ‘Save This View’ Button
This option is checked by default. When unchecked, it will allow view modifications to be saved as a new view. When a user is looking at a list or library in SharePoint, as soon as they start clicking column headings for sorting and filtering, the Save This View button appears. I love this! A lot of times, I’ll put a web part on a page, and use “edit the current view” a few times, to get it looking the way I want. Then, if I want to do the same thing again, or on another page, I’d have to do that work again if I didn’t create it as a view in the first place. This allows me to save my view and choose public or private and give it a name. Keep in mind that this button will not appear until you click to sort or filter your columns. Also note that as always, if an end user does not have permission to create public views, of course their only option will be to create a private view.
Display search box
The search box at the top of lists and libraries is awesome! Now, this gives you the ability to display this small search box right in your web part, so users can quickly search through the files in that list/library and immediately see the results right in the web part without having to navigate away!
Takes away all of these checkboxes that I’ve described in this post, and removes any added functionality that they provide.
This is a web part with the view selector, save this view, and search box all showing:
Important note! These settings only exist with the default style in your views. In your view settings (not web part settings), if you have changed the style to anything but Default, none of these web part settings will be available to you.
I’ve recorded a video demonstrating all web part settings. Click on the image below to jump straight to the part where I start talking about these Miscellaneous settings.
It’s time for the SharePoint Technology Conference (SPTechCon) in Boston again! You can use the code ROGERS when you register, to get $200 off of the cost. What’s going on this year?
Here’s my schedule for the week:
| || |
11:00am - 12:15pm
Making the Most of the Out-Of-Box Web Parts
There are over 50 out-of-the-box Web parts in the enterprise version of SharePoint! In this class, you will learn just how flexible and useful these Web parts are. Not only will you get a detailed look at the Filter, Excel, Social, Rollup and Media Web parts, but you will also learn about a few new ones in SharePoint 2013 such as the Content Search Web Part. You will then learn how to customize some of these Web parts, see examples, demonstrations, and learn about new features. All of this is done without writing any code. Push SharePoint as far as you can with out-of-box functionality! This class is a mixture of 2010 and new 2013 Web parts.
| || |
8:30am - 9:45am
Creating an Approval Workflow, Part I
Forms and documents are everywhere in your organization, and a lot of them must go through an approval process. SharePoint is such a flexible platform it provides us with multiple methods that can be used to build our processes. In this class, learn about these different out-of-box ways to create a workflow around a form approval process. You will see the various alternatives when creating an approval workflow such as content approval, out-of-box workflows, and the task process designer in a SharePoint Designer workflow. Quickly create and implement intuitive workflows for your critical IT and business systems with no programming involved! The concepts in this class are applicable to both SharePoint 2010 and 2013. This is part one of a two-part class, covering only the simple and purely out-of-box settings and functionalities.
10:00 – 10:45
Enterprise Forms Panel
10:45 – 12:00
Meet up with experts in Exhibit Hall – Information Worker
3:00 pm – 3:15 pm
Jennifer Mason, Amanda Perran and Laura Rogers – Beginning SharePoint 2013: Building Business Solutions
| || |
8:30am - 9:45am
Creating an Approval Workflow, Part II
Forms and documents are everywhere in your organization, and a lot of them must go through an approval process. SharePoint is such a flexible platform it provides us with multiple methods that can be used to build our processes. Quickly create and implement intuitive workflows for your critical IT and business systems with no programming involved! In this advanced class, learn about creating a completely custom new hire approval process. In part two of this class, we will build out an HR onboarding workflow in SharePoint Designer, using a complex example that involves a process with both serial and parallel components with multiple workflows. The concepts in this session are applicable to both SharePoint 2010 and 2013. This is part 2 of a 2 part presentation. This second part has only advanced concepts geared towards those who are already familiar with SharePoint Designer workflows, and does not contain any of the out-of-box workflow options taught in part 1.
Every Wednesday at 11 AM Central time, some colleagues from Rackspace and I do a live YouTube / Google Hangout broadcast called SharePoint Power Hour.
Recently, I did a series of videos where I outline a single business process in detail. I decided that a New Hire Onboarding process is a very common scenario, so that’s what I decided to create. First of all, here are some associated files for you:
Hour 1 – I go through some slides describing the business process and my pet peeves with out of box workflow and tasks. In the last 20 minutes I start building the whole solution from scratch. I create the New Hires list, the new Hire Content type, site columns, and then I create the Promoted Links list.
4:13 Explanation of the solution
5:40 Some slides
8:20 Visio diagram of the workflow
20:01 Show a demo in the SharePoint site
30:45 Laura realized that her workflow was working fine along even though she was trying to troubleshoot it :-)
32:44 Explanation of why to use the Create List Item action instead of task actions
37:09 An overview of the workflow in SPD
37:50 Create a new site, to start building this whole solution from scratch
39:31 Creating all of the lists on the site
40:32 Explanation of creating the New Hire as a content type with site columns
52:45 Look at the New Hire form after finishing the list
53:11 Create the Promoted Links list
56:57 Insert the Promoted Links as a web part
57:29 Wrap it up for today
Hour 2 – I start building the new hire approval workflow in SharePoint Designer 2013, I create several Task content types. I finish building the Set Variables stage and the Manager Approval stage.
4:00 Begin the overview of what's happened so far with the solution
5:36 Discuss the concepts behind how the workflow will be built
8:26 Fill out the first new hire form
11:17 Modify the default view of the new hires list
18:26 Open SharePoint Designer to start on the workflow
20:20 Demonstrate the visual workflow designer
23:59 Add the manager approval actions to the workflow
24:45 Discuss the Workflow Tasks list and task content types
34:03 Finish creating the Set Variables stage
37:13 Publish the workflow and run it as a test
38:08 Add logging to the workflow
39:50 Create more Task content types
52:32 Create the New Hire lookup site column
55:48 Add the new hire lookup to the Create Item action
58:40 Add a condition in the transition to stage in the workflow
Hour 3 – I finish up the manager approval stage, and move on to the three parallel task. I explain how I make the workflow wait until all 3 of those tasks are finished before it moves on.
4:39 Overview of the workflow
6:52 Open the workflow in SPD, overview of it so far
9:39 Rant about a frustration with 2013 workflows
11:12 Answer a question about promoted links list
12:02 Pick up where we left off at end of manager approval
12:35 Create a workflow on the task list
13:45 Lori asks a question about the workflow start options
15:33 Add the first condition and action to task WF
19:22 Test the workflow so far
19:35 Add the transition after manager approval stage
20:30 Talk about GoTo actions and meaning of stage names
21:35 Fill out a test new hire
25:00 Check workflow status screens on both lists, troubleshoot
26:04 Fix the task workflow and re-publish
27:26 Add logging to task workflow
28:33 Back to new hire workflow, stage 3 parallel tasks
30:13 Create SharePoint groups for roles within workflow
32:01 Back to workflow, put SP Groups in assigned tasks
34:05 Discuss the due date variable
34:52 Add all three of the actions for the parallel tasks
37:43 Explanation of logic waiting for 3 parallel tasks
40:00 Create new site column for new hire list, Parallel Count
42:45 Add site column to New Hire content type
44:11 Back to workflow to utilize that new column
49:02 Rant about Else-If pet peeve in 2013.
50:00 Answer question about looping through mult tasks Post I wrote on that
59:25 wrap up
Hour 4 – At the beach! In this segment, I finish up the parallel task stage, and add the security task stage. Then, I create the new hire dashboard and run through the workflow.
4:01 Overview of workflow diagram
5:08 Fill out a new hire, run through WF so far
11:43 Pick up where we left off in the 3 parallel tasks in WF
12:19 create transition to diff stages according to approve or reject
14:10 After 3 parallel tasks completed, MATH. Go to next stage.
15:32 Open task list workflow, add new condition.
18:40 Back to new hire list wf, add stage for security task
20:36 Add the Department site column to New Hire content type
21:46 Back to WF, create conditional transitions and all stages
25:50 Add security task stage actions
29:40 Back to task workflow, add another condition
29:55 Organize the task workflow so that the conditions aren't nested
34:22 Add the security task condition to the task WF
38:40 Add a test new hire
40:10 Start creating the new hire dashboard
46:30 Workaround for the inability to do web part connection to tasks
49:05 Create custom action / quick step to get to dashboard
53:12 Go back to the new hire being tested, run through wf
57:15 So far so good. Go to questions.
Hour 5 – Home with the baby. I finish up the workflows, do a test run-through, and create a couple of views.
9:20 Overview of workflow task order
10:00 Workflow in SharePoint Designer
11:49 Go to where we left off, the HR Approval stage
17:22 Open task list workflow, add new condition and action
22:00 Add a bunch of logging to task workflow
22:55 Back to new hire list workflow
25:00 Go to Employee Orientation stage
28:00 Talk about the task wf and then go add another condition to it
29:38 Move on to the completed stage of new hire workflow
30:45 Stephen mentions linking a task list to Outlook
33:15 Set the Task content type required fields
34:25 Do a test run-through of the whole workflow
38:36 Troubleshooting: modify the required and hidden fields
40:50 Add another new hire, test again
46:10 Troubleshooting stuck workflow. Fix it.
49:49 Create "in progress" view of new hires list, add promoted link
53:30 Adding / editing more views of various lists and on dashboard
54:11 One more run-through of a test
Hour 6 – Whew! Fix the due date column, modify some web parts and navigation to generally clean up the whole user interface. Discuss permissions options.
3:22 Overview of solution
5:58 Fill out a new hire, start going through process
10:30 Answer question about how the dashboard was created
11:15 back to walking through the workflow
13:43 Fix due date column to show date and time
20:35 Modify web parts on home page
27:55 Modify navigation
31:03 Modify the new hire dashboard
38:48 Talk about permissions
40:43 Define who can see what
43:13 Modify permissions
44:20 (Rant about the "Edit" permission level in 2013 / O365)
53:08 Activate the App Step feature
I hope you have liked this series, and stay tuned to our upcoming Power Hours:
Finally! It can be done with a SharePoint Designer 2013 workflow! This is something that I’ve been wanting to be able to do for YEARS, and now it’s possible… and I’m just now blogging about it. No, this can’t be done in any previous versions unless you go buy a 3rd party tool or get a dev to write something custom.
Think about any time you’ve wanted to be able to edit multiple items in a list according to some condition. Think about lookups. Say you’ve got a contact list of customers, and you’ve got a document library where each document has a lookup column to a specific customer. Have you ever wanted to trigger a workflow at the customer level that would automatically go do *something* on all of the items in the other list/library that are related to that customer?
The example I’m going to use here is a very common one that you all ask me about. I want to just get ONE email letting me know about all of my currently active tasks in a task list, instead of getting all of those individual emails for each separate task. This is very complicated, so it will help tremendously if you’ve done workflows before. This post isn’t written geared to someone who has never created a workflow, because I don’t explain what any of these concepts are (like variables, etc.), I just show the steps.
So, here’s what we have.
- A list of tasks (just using the task list template)
- A list of people. This is a custom list (here I named it Loop through tasks). I added a person/group field, and called it “Assigned To” (using the existing site column). I’ve set the Title field so that it’s not required.
The idea is that the workflow will be created on the Loop Through Tasks list, and for each list item where the tasks is not completed, and the due date has passed, it will send an email to the person that lists all of those tasks. For reference, here’s the first big chunk, and scroll down to see all of the individual steps.
- Create your workflow on your list of people. I named my workflow “Test loop through tasks”, and set it so that it automatically starts when an item is created. You’ll be using a LOT of variables in here, so let’s just create them ahead of time. (Use the Local Variables button in the ribbon) Here are their names and types:
|Name ||Type |
|dictionary ||Dictionary |
|responseCode ||String |
|JSONresults ||Dictionary |
|dataset ||Dictionary |
|index ||Integer |
|count ||Integer |
|myID ||Integer |
|calc ||Number |
|Index Plus One ||Number |
|MyStatus ||String |
|StringOfItems ||String |
|myTitle ||String |
|myAssigned ||String |
|DueDate ||Date/Time |
|Add One ||Number |
- In Stage 1 of your workflow, add your first action. Build a dictionary. Click the blue word this, and your dictionary is going to have 2 items in it:
- The Build a dictionary item will then look like this. Click OK.
- The next action to add is Call HTTP Web Service. Click the first this, and put this in it:
Mine looks like this:
(How do you get the GUID? In this case, I want to look through my task list, so one way is to go to my task list in SharePoint Designer, and in the List Information section it says List ID.)
The HTTP method is HTTP GET.
- Click the blue word response, and choose your JSONresults variable. At the end where it says Variable:responseCode2, just change that to the responseCode variable (step 1).
- Click the drop-down box on this action to call the web service. Choose Properties. In the RequestHeaders box, choose the variable called dictionary. The screen should look like this (of course with your own website in the address). Click OK.
- Next, add the action Get an Item from a Dictionary. Click on the item by name or path. Type this: d/results
- Click dictionary, and choose the variable JSONresults. Output to the variable called dataset.
- Add the action Count items in a dictionary. Click on dictionary. Choose the variable called dataset. Output to the variable called count. This variable is going to tell me the total number of items in that other list, my task list.
(After this action, for fun I like to add a Log to history list action, and just log the variable called count. Logging, just in general gives me more info on my workflow status page later.)
- Add the action called Set workflow variable. Click workflow variable and select the one called index. Click value and type the number 0
This variable is going to allow me to loop through all the items in the other list, starting at zero, up to the total number of items in the list, the count.
- Add another Set workflow variable. Set the StringOfItems variable to say:
This is the variable that we’re going to use to append information to it. For each task, later we’re going to append text to this so that eventually this variable can be inserted into an email that will go to the person and list all of their tasks.
- Next, it’s time to add the loop. So in the ribbon, click the Loop button and choose to Loop with Condition.
- At the top of the loop, click the first value. Select the workflow variable called index. For the operator, select is less than. For the second value, choose the variable called count. Click OK.
Here’s a screenshot for reference, of what the whole loop is going to look like, and now we’ll go through the steps:
- Inside the loop, add the action called Get an item from a dictionary. What I originally wanted to do was to make it only get the items where the assigned to field (in the task list) equals the name of the assigned to field in my list of people here. I couldn’t for the life of me get this to work with a people field. So, instead I’m using the Status field to get only tasks that aren’t completed, and getting the due date field so that I can get just the overdue ones.
Click item by name or path. Use the string builder to do this. Most of this text is typed in there, except for the variable index I used the Add or Change Lookup button.
See where it says Status… that’s the status column in my task list. This word may be different in your own solution if you’re not dealing with tasks or statuses. How did I know to just type the word Status, when the field is called Task Status? This is important. Go to your task list settings page, and click the name of the Task Status column. Look at the URL. See the part where Field= will tell you the actual name of the column.
This part can get a bit more complicated if you have fields that have spaces or other weird characters in them. If I put a space in my column name when I created it, it will look something like Column%5Fx0020%5Fname
You then have to decode it to get what you need. Go here and put your column name in the Encoded box and click URLDecode. Then it will give you this in the Plain box: Column_x0020_name
That value is what you put in the spot where I put Status.
- Still on the Get item from dictionary action, click the dictionary. Select JSONresults. Output to, click item and choose your variable called MyStatus.
- Add another action to Get item from dictionary. Instead of the status field, this time we’ll be getting the due date. Here’s what these last two actions look like:
I’m using these two fields because that’s my “Where”. I am only going to want tasks that have a certain status and a certain range of due dates. The fields used here will potentially be different in your own solution.
- Now it’s time for a condition. Insert the condition If any value equals value. Again, this is where we use those two fields in steps 14 and 15. If the variable MyStatus not equals Completed.
- With the orange line directly under that last condition, insert another If any value equals value. And the variable DueDate is less than Today (Current Date). This will narrow down my list to only get items that are overdue and haven’t been completed.
- Inside of this IF section in the workflow, insert an action Get item from dictionary. This is similar to step 14, except this is getting the ID of each item that hasn’t been completed and is overdue.
- Next add an action to Set Workflow Variable. Set the variable MyAssigned. Click value, and click the fx (function) button. This is where I choose the Workflow Tasks (the list I want to loop through), and I want to get the Assigned To field for the items where the ID is in my list of IDs of the items that aren’t completed and are past due. The only reason I’m doing the Assigned To part here is because I wanted to do it at step 14 and that portion wouldn’t work with a people field.
- Add another action to set workflow variable. Set the variable called myTitle to the value of the task name.
- Add the action Log to History List. Log the variable called myID.
- Next, add an IF condition: If Any Value equals value. If the variable myAssigned equals Current Item: Assigned To. This will narrow down the list to only items in the task list that are assigned to the same person in the Assigned To field in the list we’re running this workflow from.
- Add an action to Set Workflow variable. Set the variable StringOfItems to this:
What the heck is all of this? This is where you create what you want the email to look like. Be sure to hit the enter key (carriage return) after you insert that first lookup to the StringOfItems. Basically I want it to show the title of each task as a hyperlink to that task, and I want to show when it’s due. This is going to loop through all of the person’s tasks that are not completed and overdue, and put them all in one big list in this variable.
- Put the cursor at the very bottom of your Loop, still inside it, and insert an action Do Calculation. Calculate the Variable: index plus 1
Output this to the variable called Index Plus One.
- Add an action to Set Workflow Variable. Set the index variable to the value of the Index Plus One variable.
This causes our loop to loop again until it’s finished going through all of the items in the task list.
- Done with the loop. Put the cursor underneath (outside of) the loop, and add an action to Log to History List. Log the variable StringOfItems. This way you can see what will get sent in the email, here in your workflow logs.
- Add an action to Send an Email. Use Workflow lookup to send it to the Assigned To field from this list (called Loop Through Tasks). In the body of the email, insert the StringOfItems variable. Make the subject say whatever you want.
- In the transition to stage section, GoTo end of workflow. Publish the workflow.
Now go add some fake tasks in your task list, and assign them to people, and then go to your list of people (the list you created this workflow on, I called it Loop Through Tasks) and add a person and watch this workflow run. Remember, don’t try running a workflow as the system account, it won’t work. After I run the workflow, here’s what I see on the workflow status page:
The count: 7 is the total number of tasks in the list. All this might take a minute if your list has lots of items in it. Then it always shows a zero, then it shows me that tasks 1, 6, and 10 are the ones that are not completed and are overdue. Then, only two of those tasks are actually assigned to my Assigned To person in the item I ran the workflow on. Those two get appended into the email text, with a link to each item and its title and due date!!
Okay here’s the next issue. How do you make this happen every day or every week or however often you want it to send these people their list of open tasks? Should be easy, right? Should just be an information management policy that would kick off the workflow. Nope, 2013 workflows can’t be triggered my an information management policy for some reason. So the easiest way is just going to make the workflow pause for whatever your duration is. Like, pause for 2 days or 7 days or whatever, using the Pause for Duration action.
- Add a new stage after your first one, and call it Pause until tomorrow. Put a single action in it, to pause for duration, such as 1 day.
- In the Transition to stage section, Go To Stage 1.
- In Stage 1, change the transition to stage so that the Go To makes it go to the stage called Pause until tomorrow.
- Publish again.
Here’s that last portion of the workflow
That first screenshot in this post, plus the screenshot at step 13, plus this last screenshot, all together that’s the whole workflow. It just won’t fit on one screen here to do one screenshot.
The next issue is, how do you auto-populate the list of people each time tasks get added to the task list? Well, you’d think you could just create a workflow that creates a person in the list if they’re not already in it. Then, each time an item was added, it would trigger the workflow that runs on item creation, and then the loop would start.
Unfortunately, SHAREPOINT 2013 WORKFLOWS CANNOT BE TRIGGERED FROM ANOTHER WORKFLOW. This means that if a new item gets added to the list via workflow, my looping workflow would not start. THIS SUCKS, because a lot of my business solutions depend on the concept of a workflow adding or changing something in a list, and that triggers another workflow to run on that item. SHAREPOINT 2013 WORKFLOWS ALSO CANNOT BE TRIGGERED VIA INFORMATION MANAGEMENT POLICY, WHICH ALSO SUCKS.
So, the solution to this is to manually create the items in the Loop through tasks list.
I did end up having to add an App Step and move all my actions into it, because I tested running this workflow as a non-admin, and it gave errors like access denied. So, here’s how to add an App Step. Skip to steps 2 and 3 in this post.
This ability to tap into web services is very powerful, and here are some other blog posts that people have written about it:
Back in 2011, I wrote a post Click to Copy List Item to New. I’ve had several requests for a re-write of this for 2013. Actually, this method I’m going to show you can be done in 2010, 2013 and Office 365.
In this concept, I’ll show you how to create a workflow that simply creates a new item and pre-populates the columns with values from the current item. In this example, I’ll be using a list called “New Hires” (which is using the contact list template). If someone has entered a new hire into the list, and wants to quickly add another one that’s mostly the same, in this case the first and last name fields would be the only difference. Here are the steps:
- In your new workflow (I’m naming mine Copy New Hire), click the button in the ribbon called Initiation Form Parameters.
The reason we’re doing this part, is so that when they click to copy a new hire, they will be presented with a form to fill out the first and last name of the next new hire.
- Click the Add… button, and the first Field Name will be called First Name. Keep the default information type as a single line of text. Click Next.
- Leave the default value blank, and click Finish.
- Repeat step 2, creating a second field called First Name the same way.
- On the Association and Initiation Form Parameters screen, click OK.
- Add an action to your workflow, called Create List Item. Click the blue words this list.
- For the List drop-down box, I’m choosing my New Hires list, so I’m really just creating a new item in the same list that I’m running the workflow in.
- Any required fields in your list will automatically show here with asterisks next to them. Also, if you’re using multiple content types in your list, the Content Type ID field will show. Click to select the Last Name field, and click the Modify button.
- Where it says To this value, click the fx (function) button. For the data source, choose Workflow variables and Parameters. For the Field from source, choose Parameter: Last Name. Click OK. (twice)
- The idea is that although we’re going to copy this item to be a new one, there are usually going to be one or two fields that are going to be different. Those are the ones that we create as parameters to pass to the new item. In this case, it’s just first and last name, so all of the other fields will end up getting set up with the same value as the item we’re copying. In this case, the last name was the only required field, so it was the only one showing on the Create new List Item screen. I still have to add a bunch of other fields here. Click the Add button. For Set this field, choose First Name. For To this value, repeat what you did in step 9 for the last name, except this time you’re using the parameter called First Name. Click OK.
- Now that the two parameters have been added (you may have more in your own solution, however many you need), it’s time to add all the rest of the fields. Click the Add… button. City is going to be my next one, so for Set this field, I choose City.
- Click the fx (function) button next to To this value. The Data source should be Current Item, and for the Field from source, I choose City also. Click OK. Click OK.
- My next field is going to be Company. Repeat steps 11 and 12, but instead of choosing City in both places (in purple), I choose Company.
- Repeat steps 11 and 12 for all of the other fields in your list that you want to be pre-populated when the new item (copy) gets created. Notice in this screenshot that the first and last name fields are from parameters, and all the others are just going to be a copy of what is in the current item.
- When you’ve finished adding your fields, click OK. If you are using a SharePoint 2013 workflow, you’ll need to add a Go To action in your Transition to stage, but then the workflow is ready to publish! (I also gave my stage a pretty name other than Stage 1)
- In your New Hires list in SharePoint, go to the List tab in the ribbon and click the button New Quick Step. Alternately, you can open SharePoint Designer, go to Lists and Libraries, and click the name of your list there. The Custom Actions are the exact same thing as Quick Steps.
- Instead of using the generic screen for creating a new custom action, called Create Custom Action, click cancel. Put your cursor in the section at the bottom called Custom Actions. Once you do that, you’ll see Custom Actions in the ribbon, with the drop-down box for a new Custom Action. Here’s where it is when you’re on that list’s settings page in SPD:
- Click the Custom Action drop-down box in the ribbon. Choose List Item menu. Keep in mind that you can create many different types of custom actions that all do the same thing, these custom buttons will just show up in different places such as the list item menu, the Display Form ribbon, etc.
- Name your custom action Copy to New. Or you can call it whatever you want, really. Type a description, so that people will know what this button does. In the section called Select the type of action, choose Initiate workflow. Choose the workflow you just published, mine is called Copy New Hire. Click OK.
Extra notes: Keep in mind that if you have images that are 16x16 or 32x32, stored in SharePoint, you can fill in the button image URL field as well. Also, in this workflow’s Start Options, I have it so that it can be manually triggered. If your workflow is not allowed to be manually triggered, it will not show up in the list of workflows to select from when choosing Initiate workflow as the action for your custom action.
- Now, when I go to my New Hires list in the browser, and I click the ellipsis or drop down box on an item in the list, “Copy to New” is now an option in that drop-down. I click it, fill out the parameters, and then as soon as I click Start, the new item gets created.
That’s a pretty simple solution, but there are a couple of issues. The initiation parameters don’t allow us to do required fields, so it will allow people to kick off the workflow without actually filling in the parameters. If a fields is required, it would then have the words “No Title” in it, instead of any actual first or last names.
Another issue, is that after the workflow runs, it bounces the user back to the homepage of the site. So although the item does get created, they don’t immediately see it. One super simple solution to this would be to put a list web part on the homepage called “My New Hires” and make it have a filter of “Created By” is equal to [Me] and for it to be sorted by the Created date descending. That way, even though they get bounced back to the homepage, they’ll immediately see the item they just created.
Here’s some more info about custom actions / quick steps:
Next Saturday, June 21st is the first ever SharePoint Saturday in Baton Rouge, and I’ll be there! Unfortunately, it’s the same day as SharePoint Saturday Atlanta, which I usually go to, but since Baton Rouge is my hometown, I simply can’t miss it!
I’ll be presenting two sessions. Here’s the detailed info. Can’t wait to see you there!
Making the Most of the Out-Of-Box Web Parts
There are more than 50 out-of-the-box Web Parts in the enterprise version of SharePoint! In this class, you will learn just how flexible and useful these Web Parts are. Not only will you get a detailed look at the Filter, Excel, Social, Rollup and Media Web Parts, but you will also learn about a few new ones in SharePoint 2013, such as the Content Search Web Part. You will then learn how to customize some of these Web Parts, see examples and demonstrations, and learn about new features. All of this is done without writing any code. Push SharePoint as far as you can using out-of-box functionality! This class is a mixture of 2010 and new 2013 Web Parts, most of them are only available in the Enterprise version of SharePoint
Seven Pro Tips to Become a Workflow Rock Star
Track: IT Pro, Developer, Business
In SharePoint workflows, there are several tricks of the trade when it comes to creating successful workflow solutions. In this SharePoint 2010/2013 session, Laura Rogers will teach you the seven main things to know when working with workflows. One of the most important skills to have will be the ability to troubleshoot and track your workflow. In addition, you will learn how to insert logging and even receive email notifications when something goes wrong with your workflow, as well as how to create beautiful workflow emails…and much more. This session is geared toward people who already have experience with workflows, and would like to hone their skills.
Someone recently had a question on one of my workflow blog posts. The goal is to set a deadline of the 14th of the month for one document type, and the 29th of the month for another type. This is going to entail using a workflow to figure out what the create date is, and then assign a due date relative to that. This can be accomplished using some really useful actions in a workflow, and it applies to 2010, 2013, and Office 365.
What do I need for this example? A list or library with a due date field added, and a choice field called document type, where the options are “Policy” or “Contract”.
It all starts with obtaining an ISO formatted date, and using it as a variable…
- Add the action: Set Workflow Variable
- Click the blue words workflow variable, and click Create a new variable…
- I’m going to base mine off of the Created date field, so I’m going to name the variable Created ISO. Make sure you select String as the Type. Click OK.
- Click the blue word value, and then click the function (fx) button. Leave the data source as current item, pick your date field as the field from source, and for Return field as, be sure and pick ISO Formatted. Click OK.
- Now you need to see what this format looks like, so you can work with it and get what you need out of it. For the next action in your workflow, do a Log to history list. Click the blue word message, and then click the function (fx) button.
- We can just look at this value as a string in our log, to use it as a reference, so we will know what the syntax is. Data source is Workflow Variables and Parameters, field is the Created ISO variable, and return field as String.
- We’re going to publish it next, to see what the result looks like. If you’re using SharePoint 2013 or SharePoint Online, you’ll see a Transition to Stage section in your workflow. Put GoTo End of Workflow in there. Here’s what your whole workflow looks like so far:
- Publish the workflow, and run it on an item in your list or library that you created the workflow on. Click the Workflow Settings button in the ribbon, click Open Associated list, and then hit the F12 key to quickly get there. On my status page, this is the information that was logged by the workflow.
If you’re new to SharePoint, here’s some basic info on how to get to the workflow status screen for an item, in addition to a ton of other workflow beginner basics.
- The syntax of the ISO formatted date is as follows:
Just break it down to where all of the important parts are. The first character is considered 0.
Year: characters 0 through 3
Month: characters 5-6
Day: characters 8-9
If you live in a different country, your date may have a different syntax than mine. Obviously you can see that the time is here as well, if you need to extract that info for any reason.
- We need to get the month. Go back to your workflow in SharePoint Designer. After your Log action, add the action called Extract Substring of String from Index with Length.
- Click the blue word string. Click the fx (function) button and choose the data source of Workflow Variables and Parameters, the Field is Variable: Created ISO, and return field as string. Click OK.
- Where you see Starting at 0 for 0 characters, click on the first zero. Type a 5. Click on the second zero, and type 2.
- Where it says Output to Variable:substring, click the name of that substring. Choose Create a new variable… Name it Created Month, and click OK.
- Repeat step 11. Where you see Starting at 0 for 0 characters, click on the first zero. Type a 8. Click on the second zero, and type 2. Create a new variable again, name it Created Day, and click OK.
- Repeat step 11 again. Where you see Starting at 0 for 0 characters, click on the first zero. Type a 0. Click on the second zero, and type 4. Create a new variable again, name it Created Year, and click OK.
- We are going to need to be able to do math on these numbers that have been extracted from the created date. Right now they are string variables. Next, we will convert each one to an integer variable. Put your cursor after the action that you created at step 13. Add the action called Set Workflow Variable.
- Click on the blue words workflow variable, and click Create new variable… Name it MonthInt, and the type is Integer. Click OK.
- Click on the blue word value, and click the fx (function) button. The data source is Workflow variables, field is Created Month, and return field as integer. This basically takes the text value that we already stored in the Created Month variable, and converts it to an integer. Click OK.
- Do the same thing after each of the other two portions of the date, the day and the year, adding two more variables also. The workflow should look like this so far:
- Since the type of document called “Policy” is due on the 14th of the month, we need to look at the created date and see if it’s before or after the 14th of the month. If it’s before, then we can set the due date to this month, if it’s after, the due date needs to be the 14th of *next* month. Add a condition to your workflow. If any value equals any value.
- Click the first value, and select the Document type field from the current item data source. Click the second value, and choose Policy.
- Inside of this condition, add the action Set workflow variable. Create a new variable called Due Day of Month, as an Integer. For the value, type the number 14.
- With the cursor on the action you just added, click the Else Branch button in the ribbon. Under the word Else, add the action set a workflow variable. Set the Due Day of Month to the value 29. We only have two policy types in this library, so our else statement is simple, if it’s not a policy, it’s a contract.
- Outside of the condition you just added, after it, add the action Do Calculation.
- Click the first blue word value and click the function (fx) button. For the data source, select Workflow variables and parameters, and for the field, pick Variable: DayInt
- Change the word plus to minus. Click the second blue word value, and use the function button to pick the workflow variable called Due Day of Month. Where it says Output to, click the drop-down and Create a new variable. Call it Subtraction Result. This is what the action looks like now:
- Under the calculate action that you just added, add another condition. If any value equals value. For the first value, pick the Subtraction Result variable, and then select is less than, and type the number 1.
- Now we have to construct a new variable using the date of the due day of the month. We will create it as a string, and then we will have to convert that to a date variable. Under (within) the condition you just added, Add the action called Set workflow variable. Create a workflow variable called “Due Date String”, as a string variable.
- Click the blue word value. Click the little ellipsis (and not the fx button).
- In the String Builder, first use the button Add or Change Lookup to insert the variable called Created Month. After that, type a backslash, and add the next lookup, etc, so that your full string looks like this. This is formulating the date of the 14th of the month, at 8AM.
- Next, we’re going to put in the else condition, though, so that we can say what the date will be of the 14th or 29th of *next* month. Click the Else Branch button in the ribbon. Under the word Else, add the action called Do Calculation. Calculate the Variable: MonthInt plus 1. Output it to a new number variable called Next Month.
- Repeat steps 26 through 28. The only thing different will be that in the string builder seen in step 28’s screenshot, instead of Created Month, that variable will be Next Month.
- Put your cursor outside of the else statement that your last action was in. Add the action Set workflow variable. Create a new variable called Due Date Variable, as a date variable. Set the value of this to the value of the Due Date String. THIS is what converts it from a string that we strung together in the string builder… to an actual date.
- Add the Log to history list action, click the function button in there, and select the due date variable. This is optional, and you can add a lot more of these all over the place, which is very helpful for troubleshooting.
- Add the action called Set a field’s value. Set the Due Date field in this library to the value of the Due Date Variable.
It’s a pretty complex workflow, but we managed to fit it on one page (so far)
There are some more considerations that would need to be made also. What if it’s February? What if it’s December? Use the variables created at the beginning to find out these type of things, like Created Month is equal to 02.
To make it perfect, there would need to be conditions in the workflow to solve for all of those factors. I’m looking forward to your feedback!
On April 17th, I presented Seven Pro Tips to Become a Workflow Rock Star at the live 24 hour conference called SP24. This conference is now planning an encore performance called “SP24 Rewound”, which will take place on May 14-15, in reverse order from the original.
Also, note that the PDF of the presentation is there in the session resources tab when you scroll down. You have to actually register for my session in order to gain access to this, though. When you’re looking at the whole session agenda (link above), there’s a register button next to each class. Once you do that, you’ll get an email with info about the session resources.
There were plenty of questions last time I presented this, so I figure I’d give you the answers here:
- Jen Jacobsen: Laura - do you have a blog post on creating the new hire dashboard?
I’ll be presenting this solution on May 14th at SharePoint Power Hour at 11 Central.
- maridee oday: (regarding my demo of creating a task using “Create list item” action instead of “Start Task Process”) if you used the task creation as designed through SP designer instead of creating a list, would the workflow automation work better in O365 version of SP?
No, this works the same in workflows in SharePoint 2013 on premises and Office 365.
- Timo Pitkäranta: @laura/kkhipple Q1: if customer has done a workflow by themselves and they want their to develop the process further by us (because OOTB workflow does not meet their needs), how to do that? start from beginning?
Yes, you’d have to create a new workflow using SharePoint Designer, because an OOTB workflow can’t be customized any further than what you already get in the user interface (checkboxes, etc.)
Q2: when to do custom workflow instead of e.g. information management policy or timer job/custom code?
When an out-of-box workflow doesn’t have an action to do something specific that you need to be able to do in that workflow… then do custom dev or buy a 3rd party product.
- Fred Y: What is the impact of adding too many logs on workflow history?
Your workflow history list can get extremely large, because it doesn’t automatically keep itself cleaned up. You’ll notice that tasks associated with a workflow (using the task actions) will automatically disappear after 60 days by default. In the past I’ve had to use PowerShell on the server to clean up the workflow history list because it got too large. Here’s a related blog post that I wrote: SharePoint Workflow History Issue
- Natalia Tsymbalenko: Question. How can I do custom action for SP Worfklow on SPOnline?
I’m not a dev, so I looked online and this is what I found: http://sharepoint.stackexchange.com/questions/73626/how-to-develop-a-sharepoint-designer-workflow-action-for-use-in-sharepoint-2013
Damien Frost: I experience a problem with 'recurrence' step of Information Management Policy fails to trigger workflows after the first run. Is this something anyone else as run into (Office 365 only)
This doesn’t surprise me, but I’ve only seen it happen sporadically. I’ve also noticed that Information Management Policies won’t trigger SP 2013 workflows, only 2010 ones, which is unfortunate.
Elena Schott: Recommendations for HTML editor that's under $100? (Company won't buy it but I would)
SharePoint Designer 2010 is free and will let you do this. Also, you can go into any rich text field or wiki page in SharePoint (like the body of an announcement in an announcements list) and you have WSYIWYG and you can then click the “Edit Source” button (in the Format Text tab of the ribbon) to see the code behind what you just did visually in the body of the announcement or page you’re on.
Geetha Sivasailam: Questions: SPD 2013 provides the ability to copy/paste activities within the same workflow or from 1 workflow to another. But doing that has crashed SPD for me. Have you experienced that?Is that a known issue?
No, doing copy and paste has never caused mine to crash. Not sure if it’s a known bug. Here’s Microsoft’s blog post about copy and paste: http://blogs.msdn.com/b/sharepointdesigner/archive/2012/08/10/copy-and-paste-support-in-sharepoint-designer-2013.aspx
Natalia Tsymbalenko: @Laura, what about APPROVING VIA EMAIL NOT GOING TO SP?
There is no out-of-box functionality that does this, but I know that some of the 3rd party workflow products have it built in. Also, I had someone tell me once that they figured out a way to do it, so that the user received the approval email with a hyperlink in it. That hyperlink created a new email TO the email address of a email-enabled library. Then that library had a workflow on it that sent info back to the original list that they were actually approving. They had to do something special in PowerShell on the server, to make it so that the email arriving in the library would actually trigger the workflow (because it doesn’t do this out-of-box). Email-enabled libraries are not available in Office 365.
Elaine Rafferty: what is the web address for the SharePoint power hour?
Here is the playlist of all of our past ones.
Here is where you can see upcoming events and even add them to your calendar.
Geetha Sivasailam: Question: SPD workflows have 50 variable limit. What's the best way to handle this limitation?
Click on Local Variables in the ribbon and delete any that you are not using. Also, you can reuse them if necessary and possible with your logic. For example, when I create an item using “create list item” action, I can name name something like “ListItem” and use that same variable name for each list item I create.
Brian Call: That alert will not go off if a workflow edits an item correct?
Unfortunately, that’s true with 2013 workflows. If a workflow edits an item, this will not trigger the workflow on the item that the workflow edited. This is a huge negative to me.
R0b3r70: from time to time, some workflows seem to be stuck in progress and doesn't complete or error or anything. what can you do with such WFs?
This is one of the reasons that I don’t like the task process designer. I don’t like to leave workflows running in progress.
Brian Call: @Laura do you ever worry about the number of workflows running at once?
Yes, I don’t like to have a bunch of workflows running in progress on a bunch of items… just waiting. As far as scalability, at least now in 2013, you can have a whole server dedicated to workflow, and even a whole workflow farm.
Ricky Singh: So, if we need to send reminders for due date like 2 days before, that can be done using Information Management Policy?
Here’s an old blog post I wrote on the topic: Workflow- Reminder Before Due Date – MOSS vs. WSS
Fred Y: Is there a page where we can see what active workflows are running?
Not really at the site level, but for each list/library, you can create a view where you can see the column that has the same name as your workflow, and filter/sort that.
Svetlana Avramova: On Office 365 Microsoft removed the Alert me on a View. Do you have any information about this, and are they going to put it back there, or we need to build more workflows.
They did not remove it from Office 365. That demo where I just showed it was in Office 365. Here’s my blog post on the subject. And oldie but goody. Alerts Based on Views
7 Pro Tips
In addition, here are my 7 pro tips and some resource links to go along with them.
- Use Logging
mentioned in: Workflow actions quick reference (SharePoint 2013 Workflow platform)
- Pretty email formatting
This is the only one I could find. It says 2010 but applies to both 2010, 2013, O365: http://sharepointjim.wordpress.com/2011/07/25/how-to-create-rich-html-email-message-in-sharepoint-designer-2010-workflow/
- Understand troubleshooting
Couldn’t find any good web resources specifically about troubleshooting, but there’s this great Workflow Resource Center by Microsoft.
- Create workflow error notifications
This part is based on my blog post Get Notified of Workflow Errors which doesn’t appear to apply to 2013 because it doesn’t look like errors get stored in the same place now.
- Use a custom history list
This tip is a very specific one that I came up with, there are definitely not any MS resources about it. This is described in my session, though.
- Use variables
This resource is for SP 2007, but it is the most thorough MS resource I could find, that explains what variables are.
- Understand Information Management Policies
Introduction to Information Management Policies
I’ll see you all at my session on May 14th, and this session is recorded and will be available on YouTube afterwards.
Yes, this is overdue, but better late than never…
SharePoint Conference (SPC) was in Las Vegas in March. Here is the recording of the session that Jennifer Mason and I did, called
Tips & Tricks to make the most out of your SharePoint site and maximize adoption
This is a very basic session, geared towards power users and site managers. A lot of the tips we mention have been around for a few years, and some of them are brand new. With each tip we cover, we give you some resource links that will help you go further with that solution. Here is our spreadsheet of links.
Also, while at SPC, Karuana Gatimu interviewed me for SPCtv. We talked about requirements gathering for automating business processes in SharePoint.
SPCtv Laura Rogers Talks About No Code Solutions
Last week was SPTechCon in San Francisco. I taught 4 sessions, and uploaded the PowerPoint files to my blog:
The one called “Creating an Approval Workflow” was a fun new one. I went over the easy, out of box ways of doing approvals in SharePoint, then went into a more real-world scenario with a more complex workflow. There is also a zip file in there associated with this presentation, which has the actual workflow diagrams I exported from SPD. Here are the files:
- Creating an Approval Workflow.pdf – This is the PowerPoint presentation
- Creating an Approval Workflow – New Hire Demo.pdf – This is the diagram of the complex workflow
- Creating an Approval Workflow – Diagrams to import to SPD 2013.zip – This is the workflow itself, exported from SharePoint Designer 2013.