Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

May I know how to create a button in a customized aspx file (designed by SharePoint Designer 2007) that when pressed, it trigger a workflow in a SharePoint form library?

Scenario: A web-based form (not InfoPath form but a aspx-customized form) that can trigger a workflow that is inside a SharePoint form library.

share|improve this question
add comment

3 Answers 3

up vote 2 down vote accepted

Here are a couple examples from sites where I have implemented this. Both options are based on hyperlinks (but could be adapted to buttons) This first example shows how to do it directly.

I have a DVWP with this markup:

<a href="https://my.spsite.com/sites/submit/_layouts/NintexWorkflow/StartWorkflow.aspx?List=4f988f8a-336e-4154-b045-d083fa0371a1&amp;ID={@ID}&amp;TemplateID=%7Beefc705f-b3ad-43fb-9fc8-615fb1226955%7D&amp;Source=https%3A%2F%2Fmy%2Espsite%2Ecom%2Fsites%2Fsubmit%2FPageLib%2FAdmin%2FDashboard%2Easpx">Copy Request</a>

It is calling a Nintex workflow in this case but it could be any workflow you've created. You can gather all the information by going to a list item and going into the manual initiation screen.

The other option I have a DVWP that has this code. On clicking the hyperlink, it executes some jQuery triggering my workflow. It uses Marc Anderson's SPServices library.

<xsl:attribute name="id">
                    <xsl:text>WorkflowTD</xsl:text>
                    <xsl:value-of select="@ID" disable-output-escaping="yes"/>
                </xsl:attribute>
                <a href="#">
                    <xsl:attribute name="onclick">
                        <xsl:text>javascript:StartWorkflow(&apos;https://</xsl:text>
                        <xsl:value-of select="$Host" />
                        <xsl:value-of select="@FileRef" disable-output-escaping="yes"/>
                        <xsl:text>&apos;,&apos;</xsl:text>
                        <xsl:value-of select="@ID" disable-output-escaping="yes"/>
                        <xsl:text>&apos;);</xsl:text>
                    </xsl:attribute>Copy Request</a>

Then I have a script that looks like this:

<script type="text/javascript">
function StartWorkflow(ItemURL, ItemID) {
var workflowGUID = null;
$().SPServices({
  operation: "GetTemplatesForItem",
  item: ItemURL,
  async: false,
  completefunc: function (xData, Status) {
    $(xData.responseXML).find("WorkflowTemplates > WorkflowTemplate").each(function(i,e) {
      // hard coded workflow name
      if ( $(this).attr("Name") == "Copy" ) {              
        var guid = $(this).find("WorkflowTemplateIdSet").attr("TemplateId");        
        if ( guid != null ) {
          workflowGUID = "{" + guid + "}";
          }
        }
      });
  }
});

var workflowTD = '#WorkflowTD' + ItemID;
  $().SPServices({
    operation: "StartWorkflow",
    item: ItemURL,
    templateId: workflowGUID,
    workflowParameters: "<root />",
    completefunc: function() {
      $(workflowTD).html("Workflow Started");
    }
  });
}
</script>
share|improve this answer
    
[Q1] for your 2nd option, you mean that I just need to copy the first set of code to a data view web page and the second set of code to a normal aspx will do the trick? [Q2] I find that the SPService library is for SharePoint 2010, do correct me if I find it wrongly, is there for SharePoint 2007? [Q3] If the SPService library can be used for SharePoint 2007, do one still need to go to the SharePoint server to install / run it just like Visual Studio which need to be install togethrer with SharePoint 2007 Server? –  Larry Morries Sep 20 '11 at 8:30
    
1, the XSLT and the script work in conjunction with each other. THe XSLT renders the HTML that executes the javascript. 2. SPServices works for both 2007 and 2010. 3. SPServices and jQuery can be uploaded to a document library in the site collection they are going to be used. They don't have to be bundled into a feature and deployed like a VS solution. –  PirateEric Sep 20 '11 at 12:04
add comment

Try the accepted answer on this MSDN thread

http://social.technet.microsoft.com/Forums/en-US/sharepoint2010programming/thread/d9d0bb0a-e53c-4a44-9ab1-a15e191834f2/

share|improve this answer
    
[Q1] for the SPList inside the link you provided, does the code belong to Visual Studio C# coding, do correct me if I am wrong? –  Larry Morries Sep 20 '11 at 8:32
    
@LarryMorries Yes it belongs to the code you write in Visual Studio C# coding –  Daniel Ziga Sep 20 '11 at 9:19
add comment

I cannot get your code (below) to work. when link clicked I recieve error and the url then displays ...ID={@ID}, it takes url ID bit literally and not the value.

<a href="https://my.spsite.com/sites/submit/_layouts/NintexWorkflow/StartWorkflow.aspx?List=4f988f8a-336e-4154-b045-d083fa0371a1&amp;ID={@ID}&amp;TemplateID=%7Beefc705f-b3ad-43fb-9fc8-615fb1226955%7D&amp;Source=https%3A%2F%2Fmy%2Espsite%2Ecom%2Fsites%2Fsubmit%2FPageLib%2FAdmin%2FDashboard%2Easpx">Copy Request</a>

My code is below:

<a href="http://sp20104/HitsMissesApp/_layouts/IniWrkflIP.aspx?List={deff1c34-4aec-43ad-b1e8-00444d3ab674}&amp;ID={@ID}&amp;TemplateID={0db61b7a-1517-421b-86f6-ac2ee13c95cd}&amp;amp;Source=http%3A%2F%2Fsp20104%2FHitsMissesApp%2FLists%2FHitsandMisses%2FAllItems%2Easpx">clicke here</a>

I've tried several ways but it does not process, Is there a setting in SP that i've missed?

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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