Home > Client object model, Content Editor Webpart, javascript, jQuery, Nintex Workflow 2010, SharePoint 2010 > How to create a link to Nintex Start Workflow Page in the document set home page

How to create a link to Nintex Start Workflow Page in the document set home page

In this blog post, I’d like to show you how to create a link to start Nintex Workflow Page in the document set home page.

1. Firstly, you need to upload the latest version of jQuery to the style library of your team site.


2. Then, upload a text file to the style library for writing your own html and JavaScript

3. In the document set home page, insert a new content editor web part and link the text file you just upload.

4. Update the text file with the following content, you can download this file here.

<script type="text/javascript" src="/Style%20Library/jquery-1.9.0.min.js"></script>
<script type="text/javascript" src="/_layouts/sp.js"></script>
<script type="text/javascript">
$(document).ready(function() {
    listItemId=getParameterByName("ID");
	setTheWorkflowLink("YBBESTDocumentLibrary");
});
function buildWorkflowLink(webRelativeUrl,listId,itemId) 
{ 	
	var workflowLink =webRelativeUrl+"_layouts/NintexWorkflow/StartWorkflow.aspx?list="+listId+"&ID="+itemId+"&WorkflowName=Start Approval";
	return workflowLink;
}
function getParameterByName(name)
{
	name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
	var regexS = "[\\?&]" + name + "=([^&#]*)";
	var regex = new RegExp(regexS);
	var results = regex.exec(window.location.search);
	if(results == null){
		return "";
	}
	else{
		return decodeURIComponent(results[1].replace(/\+/g, " "));
	}
}

function setTheWorkflowLink(listName) 
{ 	
	var SPContext = new SP.ClientContext.get_current(); 
	web = SPContext.get_web(); 
	list = web.get_lists().getByTitle(listName); 
	SPContext.load(web,"ServerRelativeUrl"); 
	SPContext.load(list, 'Title', 'Id');	
	SPContext.executeQueryAsync(setTheWorkflowLink_Success, setTheWorkflowLink_Fail); 
}
function setTheWorkflowLink_Success(sender, args) 
{ 
	var listId = list.get_id(); 
	var listTitle = list.get_title(); 
	var webRelativeUrl = web.get_serverRelativeUrl();
	var startWorkflowLink=buildWorkflowLink(webRelativeUrl,listId,listItemId)
	$("a#submitLink").attr('href',startWorkflowLink);
}
function setTheWorkflowLink_Fail(sender, args) 
{
	alert("There is a problem setting up the submit exam approval link");
}
</script>
<a href="" target="_blank" id="submitLink"><span style="font-size:14pt">Start the approval process.</span></a> 

5. Save your changes and go to the document set Item, you will see the link is on the home page now.

Notes:

1. You can create a link to start the workflow using the following build dynamic string configuration:

{Common:WebUrl}/_layouts/NintexWorkflow/StartWorkflow.aspx?list={Common:ListID}&ID={ItemProperty:ID}&WorkflowName=workflowname.
With this link you will still need to click the start button, this is standard SharePoint behaviour and cannot be altered.

References:

http://connect.nintex.com/forums/27143/ShowThread.aspx

How to use html and JavaScript in Content Editor web part in SharePoint2010

Advertisements
  1. dave
    March 31, 2013 at 9:52 am

    this works but… Great stuff. Just what I was looking for but for me I had to modify your code and put in a “/” forward slash before “_layouts…” i.e. var workflowLink =webRelativeUrl+”_layouts/NintexWorkflow/StartWorkflow.aspx?list=”+listId+”&ID=”+itemId+”&WorkflowName=Start Approval”;
    return workflowLink; fyi thanks dave

  2. sven
    August 7, 2013 at 3:33 am

    Is there a chance to run this script in SharePoint Foundation where you don’t have a document set?

    Thanks

  3. Ramesh Chilakala
    January 9, 2015 at 3:02 am

    Hi, I am getting an error from SPContext.executeQueryAsync block in SharePoint 2013.
    any suggestions!

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: