Question

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.

Was it helpful?

Solution

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>

OTHER TIPS

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?

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top