0

I am trying to add a pop up window in a document set that shows the start a workflow page in Sharepoint 2013. I can do this easily when I include the ID of the doc set in my URL but I would like to have a URL that can be used for multiple doc sets and changed based on the ID of the doc set I am in at the moment. According to one site, the formula ID={@ID} should work but I have had no luck with that. I am thinking I need to add a function that gets the ID of the doc set and inserts it into the link but I'm not sure how to go about this. Here is the code I have been trying to use.

<button><a href="#"onclick="dialogfunction('/sites/SharePointInitiativeSandbox/Gatekeeper/_layouts/15/workflow.aspx?List={bc68b081-8590-477e-aff7-55b2b64ad3fb}&ID={@Id}'); return false;" class="btn">Start Workflow</a></button>
<script type="text/javascript">

function dialogfunction(pageUrl) {
var options = { url: pageUrl, width: 800, height: 600 };

SP.SOD.execute('sp.ui.dialog.js', 'SP.UI.ModalDialog.showModalDialog', options);

}
</script>

2 Answers 2

1

You can try several options:

Option 1. Take ID from query string. You can use this code:

JSRequest.EnsureSetup();
var idValue = JSRequest.QueryString["ID"];

This option is good it can work in all list, libraries or document sets. But if your Document Set will have folders inside it may not work, because ID will not be present in the URL. So here it is option 2.

Option 2. Use internal Document Set variable. Document set has undocumented object that has document set ID value.

var idValue = docsetHomePageData.idDocSet;

As you see solution 2 will work only with document sets.

3
  • Thanks, this looks like it should work. Where exactly should I put it in code though? When I added it to the JavaScript it didn't work and I realized that is because my link isn't in the JavaScript. Do I need to put my link in the JavaScript and if so how do I do that?
    – James11
    Jul 16, 2015 at 13:34
  • Never mind I figured it out. Under var options I set the url to page url + idValue like this and it worked. var options = { url: pageUrl + idValue, width: 800, height: 600 };
    – James11
    Jul 16, 2015 at 13:42
  • Actually it works fine in Chrome but the popup doesn't even appear in IE10, it just reloads the page(I have popup blocker turned off so it's not that). If anyone knows how to make it work in IE that would be great!
    – James11
    Jul 16, 2015 at 17:53
0

You could create a Single Line of Text field named DocSetID, set it to Hidden under each content type, then create a separate workflow that runs whenever an item is modified. Have that workflow check if DocSetID = ID, and if not, set DocSetID to ID; then reference DocSetID in your script.

Or, you could put the button portion of your code into an HTML Calculated Column and let SharePoint pass the ID value into it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.