Open SharePoint task list form in edit mode by default

This SharePoint tutorial, we will discuss how to open SharePoint task list form in edit mode by default using JavaScript or jQuery in SharePoint Online or SharePoint 2013/2016, etc.

Recently we were working in a visual studio workflow for SharePoint online site. Here we had created a few tasks, and our requirement was that if the user clicks directly from the email from the Approve/Reject link then directly it should open the Edit form of the task.

We were using the below workflow variables to generate the Approve\Reject link.

<a href=’%TaskSpecial: TaskUrl%’><b>Approve / Reject</b></a>

The above link will open the display form when any user clicks on the Approve/Reject link.

Let us say our task list display form url is like below:

https://onlysharepoint2013.sharepoint.com/sites/Bhawana/Lists/MyTasks/DispForm.aspx?ID=1

One solution we can do is we can write the below code inside a script editor web part and put inside the particular task list’s display form in SharePoint.

<script language=”javascript” type=”text/javascript” src=”https://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js”></script>
<script language=”javascript” type=”text/javascript”>

$(document).ready(function () {
var origUrl = window.location.toString();
var editUrl = origUrl.replace(“MyTasks/DispForm”,”MyTasks/EditForm”);
window.location = editUrl;
});
</script>

Or you can also put the below code inside the SharePoint master page.

<script type=”text/javascript”>
var origUrl = window.location.toString();
var editUrl = origUrl.replace(“MyTasks/DispForm”,”MyTasks/EditForm”);
window.location = editUrl;
</script>

Now when ever user clicks on Approve/Reject button from the email body it will open the Edit form directly.

But one problem you will face is even if you try to open the Display form in the task list itself it will also redirect to the Edit form. So the user will not be able to see the Display form ever.

To solve the issue you can pass some query string parameter in the link in the email approve/reject link and then you can check if the above string contains the particular string then only you redirect.

Basically, you can do some string operation to handle that.

You may like following SharePoint tutorials:

Here, we learned how to open the SharePoint task list form in edit mode by default using javascript or jQuery in SharePoint Online/2013/2016, etc.

Donwload Hub site pdf

Download SharePoint Online Tutorial PDF FREE!

Get update on Webinars, video tutorials, training courses etc.

Bijay Kumar

I am Bijay from Odisha, India. Currently working in my own venture TSInfo Technologies in Bangalore, India. I am Microsoft Office Servers and Services (SharePoint) MVP (5 times). I works in SharePoint 2016/2013/2010, SharePoint Online Office 365 etc. Check out My MVP Profile.. I also run popular SharePoint web site SharePointSky.com

>