How to Create SharePoint Workflow History List (PowerShell, CSOM, or SharePoint Designer 2013)

In this SharePoint tutorial, we will discuss the SharePoint workflow history list, how to create a Workflow History list using PowerShell in SharePoint Online. We will check how we can create a workflow history using SharePoint designer 2013.

Just to let you know that we can not create a Workflow History list from the browser in SharePoint. The SharePoint workflow history list is a hidden list.

Even if you save any workflow history list as a template, still it will not appear when you try to create a list. So we have to use either SharePoint designer 2013 or we can also use PowerShell.

Task List and History List are required for creating and deploying a workflow in SharePoint designer 2013 in SharePoint online.

SharePoint Workflow History List

If you are familiar with the SharePoint designer log to history list workflow action, then you can understand what is the use of the workflow history list in SharePoint.

When you will log any information using the log to history workflow action, the message will be saved in the SharePoint workflow history list.

When you will create your first workflow, that time the history list will get created. But it is a hidden list. So we cannot see the history list when you visit to the SharePoint Site Contents page.

You may like, Learn SharePoint Workflow.

SharePoint workflow history list URL

If you will open the SharePoint site content page, then you might be thinking SharePoint workflow history list missing.

As I said before, this is a hidden list and we can access it directly from the URL.

Below is the SharePoint workflow history list url.

https://<Site URL>/lists/Workflow%20history/AllItems.aspx

Example:
https://tsinfotechnologies.sharepoint.com/sites/SPGuidesClassic/lists/Workflow%20history/AllItems.aspx

SharePoint workflow history list missing

If you can not see the history list in the SharePoint site, then you can follow the below easiest approach to make the SharePoint workflow history list visible.

Open the SharePoint site in SharePoint Designer 2013. Then click on Click All Files from Left Navigation

Then Click Lists and then Right Click Workflow History and Select Properties

From the new window uncheck “Hide from browser” and then click on Save.

Now, the workflow history list will not be hidden anymore, you can see it from the Site Contents page also.

SharePoint online workflow history deleted after 60 days

By default, SharePoint will keep the workflow history for 60 days once the workflows completed. Then it will automatically delete the association that ties the document to the workflow history. It also deletes any tasks that were created by the workflow.

If you are using the SharePoint on-premises versions like SharePoint 2016/2013, then you can disable the Workflow Auto Cleanup timer job completely to avoid this situation.

Not only the history, it will also delete the tasks that were created in the workflow.

Create Workflow History List using SharePoint designer 2013

One of the best ways to create the Workflow History list is to create through SharePoint designer 2013.

Open the SharePoint online site using SharePoint 2013 designer. Then when you open any existing workflow or when you will create a new workflow, you can see in the Settings section, all the existing Workflow History lists like below.

sharepoint online workflow history list
sharepoint online workflow history list

There is an option to Create a New History List… also like above. Click on “New History List…” option in the above screen.

If there will be any History list presented before then it will show a warning message like below:

Changing the Association, Task, or History list for a workflow may cause the workflow to stop working properly. Before saving the workflow, ensure that list references are still valid.

how to create workflow history list in sharepoint 2013
how to create workflow history list in sharepoint 2013

Click OK. Then it will ask you to confirm “Create new Histroy list?” Click on Yes.

sharepoint 2013 workflow history list missing
sharepoint 2013 workflow history list missing

Just to want to remember one thing is that it will not ask us to give a name for the History list. It will automatically create the Workflow History name in the below naming convention.

<Workflow Name> History

If the name is presented before and you are trying to create another then it will keep adding 1/2/3…

<Workflow Name> History 1
<Workflow Name> History 2
<Workflow Name> History 3

You can see how it will create the Workflow History like below:

Create workflow list using sharepoint designer 2013 SharePoint online
Create workflow list using sharepoint designer 2013 SharePoint online

Create Workflow History List using PowerShell

We can create the Workflow History list using PowerShell. Here we need to provide the list TemplateType as 140.

You can follow this msdn article to know more about list templatetype ids. We need to also make sure, we need to provide a reference to the below dlls.

  • Microsoft.SharePoint.Client.dll
  • Microsoft.SharePoint.Client.Runtime.dll

You can run the PowerShell script using Windows PowerShell ISE or by using visual studio code.

Try{
Add-Type -Path "E:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "E:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
}
catch {
}
$SiteURL = "https://onlysharepoint2013.sharepoint.com/sites/Bhawana/"
$sListName="New Workflow History"
$sListDescription="New Workflow History"
$context = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$securePassword=ConvertTo-SecureString "***********" -AsPlainText -Force
$context.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials("bijay@onlysharepoint2013.onmicrosoft.com", $securePassword)
$web=$context.Web
$listCreationInformation=New-Object Microsoft.SharePoint.Client.ListCreationInformation
$listCreationInformation.Title=$sListName
$listCreationInformation.TemplateType=140
$list=$web.Lists.Add($listCreationInformation)
$list.Description=$sListDescription
$context.ExecuteQuery()

Once you run the above script, it will create the Workflow History list like below:

create workflow history list sharepoint online powershell
create workflow history list sharepoint online powershell

SharePoint create new workflow history list programmatically

Let us see, how to create a new workflow history list in SharePoint Online using CSOM (C#.Net). First, we will create a console application using visual studio and write the CSOM code to create a workflow history list.

Open Visual Studio 2017/2019 then click on Files from the ribbon in the top left corner to create a new project. Click on New and then on Project.

sharepoint workflow list
sharepoint workflow list

Choose Visual C# and then click on Windows Classic Desktop to choose Console App(.Net Framework).

Here you can provide a specific Name to the project and choose your location where to save the project.

By default, it will provide names and saved locations but it’s advisable to give specific name while creating Your project and choose your location. Click on OK to create a console app.

create workflow history list programmatically
create workflow history list programmatically

Clicking on OK a page Console window appears which looks like as below. Here we don’t find any other Display windows like other application platforms like a web application or normal Windows application.

Simply we need to write the code under a static void method to create a History list. Before that, we need to install the SharePoint dlls which are prerequisite as without SharePoint dlls it won’t recognize functions.

sharepoint create workflow history list programmatically
sharepoint create workflow history list programmatically

To add the dlls click on Solution Explorer where you can see References and Right Click to view more options then click on Manage NuGet Packages. you can look into the below image which illustrates.

sharepoint 2013 workflow history list missing
sharepoint 2013 workflow history list missing

Clicking on NuGet packages a window popups where you can see three options as “Browse” “Installed”  and “Updates”, Initially when the page opens it would be on Installed you need to click on “Browser”, and then type to search for Microsoft.SharePoint.client.dll and check for latest versions and publisher as Microsoft.

sharepoint create history programmatically csom
sharepoint create history programmatically csom

After Clicking on “Install” You can see Solutions is getting installed for your project. Click on “Ok” and install other dll to use a namespace in the code.

Now search for Microsoft.SharePoint.Client.Runtime.dll is also a necessary dll that needs to be installed to run the csom code perfectly and connect to Sharepoint.

Look for the latest version and Microsoft as publisher and then click on Install.

sharepoint get workflow history list programmatically
sharepoint get workflow history list programmatically

Then on program.cs to perform the coding part.

create history list using csom in sharepoint online
create history list using csom in sharepoint online

Here you get to code the CSOM coding. Before starting to code add ut using statements as so that the class and functions won’t show error messages and get underlined. Then start coding under the main statement.

sharepoint create new workflow history list
sharepoint create new workflow history list

Below is full code with all using statements and C# coding to create a history list.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint.Client;
using System.Security;
using System.Threading.Tasks;

namespace consoleapplicationtocreatehistorylist
{
class Program
{
static void Main(string[] args)
{
var siteURL = “https://onlysharepoint2013.sharepoint.com/sites/sptraining/”;
using (ClientContext ctx = new ClientContext(siteURL))
{
ctx.AuthenticationMode = ClientAuthenticationMode.Default;
ctx.Credentials = new SharePointOnlineCredentials(“bibhudutta@*******.onmicrosoft.com”, GetSPOSecureStringPassword());
var web = ctx.Web;
ctx.ExecuteQuery();
ListCollection listCollection = ctx.Web.Lists;
var listName = “NewWorkflowHistory”;
var listTitle = “New Workflow History”;
ctx.Load(listCollection, lists => lists.Include(list => list.Title).Where(list => list.Title == listTitle));
ctx.ExecuteQuery();
if (listCollection.Count > 0)
{
}
else
{
List ourHistoryList;
ListCreationInformation creationInfo = new ListCreationInformation();
creationInfo.Title = listTitle;
creationInfo.Url = listName;
creationInfo.TemplateType = (int)ListTemplateType.WorkflowHistory;
ourHistoryList = ctx.Web.Lists.Add(creationInfo);
ourHistoryList.Update();
ctx.ExecuteQuery();
ctx.Load(ourHistoryList);
ctx.ExecuteQuery();
Console.WriteLine(ourHistoryList.Title);
Console.ReadLine();
}
}
}
private static SecureString GetSPOSecureStringPassword()
{
try
{
var secureString = new SecureString();
foreach (char c in “*************”)
{
secureString.AppendChar(c);
}
return secureString;
}
catch
{
throw;
}
}

}
}

After coding click on IISExpress (Google Chrome) or start button to run the code and a console window appears where you can see a message pop-ups as the field name which is passed in the above code.

create history list using csom sharepoint online
create history list using csom sharepoint online

This is how to create a SharePoint workflow history list programmatically using CSOM (Client-side object model).

System.InvalidOperationException: Configuration HistoryListId was not found and a default value was not specified

Recently while working in a visual studio workflow for SharePoint online, I got the below error: An unhandled exception occurred during the execution of the workflow instance. Exception Details: System.InvalidOperationException: Configuration ‘HistoryListId’ was not found and a default value was not specified. And also I got another error which says: An unhandled exception occurred during the execution of the workflow instance. Exception details: System.InvalidOperationException: Configuration ‘TaskListId’ was not found and a default value was not specified.

The full error message looks like below:

RequestorId: 38d4fd8d-3663-e39c-0000-000000000000. Details: An unhandled exception occurred during the execution of the workflow instance. Exception details: System.InvalidOperationException: Configuration ‘HistoryListId’ was not found and a default value was not specified. at Microsoft.Activities.Hosting.Runtime.Subroutine.SubroutineChild.Execute(CodeActivityContext context) at System.Activities.CodeActivity.InternalExecute(ActivityInstance instance, ActivityExecutor executor, BookmarkManager bookmarkManager) at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor, BookmarkManager bookmarkManager, Location resultLocation) Exception from activity GetConfigurationValue ParseGuid DynamicActivity<Guid> WriteToHistory Microsoft.SharePoint.WorkflowServices.Activities.OperatingWebContextScope Microsoft.SharePoint.WorkflowServices.Activities.WriteToHistory Sequence TrainingRequestAddin.TrainingRequestNotification.WorkflowXaml_715346fd_61ca_43fd_8c2c_5a6df723ed57

And

RequestorId: 38d4fd8d-3663-e39c-0000-000000000000. Details: An unhandled exception occurred during the execution of the workflow instance. Exception details: System.InvalidOperationException: Configuration ‘TaskListId’ was not found and a default value was not specified. at Microsoft.Activities.Hosting.Runtime.Subroutine.SubroutineChild.Execute(CodeActivityContext context) at System.Activities.CodeActivity.InternalExecute(ActivityInstance instance, ActivityExecutor executor, BookmarkManager bookmarkManager) at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor, BookmarkManager bookmarkManager, Location resultLocation) Exception from activity GetConfigurationValue ParseGuid DynamicActivity<Guid> Sequence Microsoft.SharePoint.WorkflowServices.Activities.OperatingWebContextScope Microsoft.SharePoint.WorkflowServices.Activities.SingleTask Sequence TrainingRequestAddin.TrainingRequestNotification.WorkflowXaml_715346fd_61ca_43fd_8c2c_5a6df723ed57

System.InvalidOperationException: Configuration HistoryListId was not found and a default value was not specified

Then we wanted to manually trigger the workflow also. So in the workflow properties, I select “Manual Start Enabled”. Now next time when I deployed the workflow I got the above error.

To resolve the issue, we need to choose the Task List and History List. Select the workflow and then click on properties. Then choose the History List and Task List like below:

System.InvalidOperationException: Configuration HistoryListId was not found and a default value was not specified
System.InvalidOperationException: Configuration HistoryListId was not found and a default value was not specified

Once you select the History and Task list, the error will not come. I hope this will be helpful, to fix error System.InvalidOperationException: Configuration HistoryListId was not found and a default value was not specified.

Read some SharePoint workflow tutorials:

In this tutorial, we learned, how to create a Workflow History List using PowerShell or using SharePoint Designer 2013. In the same way, we can create a workflow history list using PowerShell and SharePoint designer 2013 in SharePoint Online or SharePoint 2013/2016.

We also saw, how to create new workflow history list in SharePoint Online programmatically using CSOM.

>