none
List View Custom Action Button to trigger Workflow to Update the List Item

    Dotaz

  • Hi,

    I am using SharePoint Foundation and SharePoint Designer 2010.  I do not have Visual Studio. 

    I have created a custom display form for my IT Helpdesk list.  On this form I have added an additional table column to the right and in this column I have added a SharePoint Data View Form Action Button called "Mark as Resolved".  This means there is a button against every list item in this view.

    When this "Mark as Resolved" button is pressed I would like the "Status" field of the list item to change to Resolved.

    I could make this button a hyperlink to a custom edit form and users could choose the Resolved drop down.  I could also create a Custom action which would place an icon in the Ribbon and could trigger a List Workflow.  However all of these require additional clicks for the user.

    My ideal is that when a user clicks the "Mark as Resolved" button once that List Item is updated.

    In SharePoint Designer 2010 I have right-clicked the Form Action button and gone to "Form Actions".  I have chosen custom action which creates a site workflow.  However I am unable to get that site workflow to apply to the specific list item and update it to "Resolved".  Looks like I need to pull through the ID of the list item somehow.

    Any ideas?

    Thanks,

    Mark

    27. února 2012 11:25

Odpovědi

  • Hello Millard1,

    Thank you for your forum posting. I can provide you with a sample code that you can add to dataview, that will generate a button that will allow you to start a workflow based on clicking that button. This is a sample code and will not work without modification.

    In the Sample code you will need to acquire jquery and spservice from codeplex

    ---Content Editor Web Part code---

    <script type="text/javascript" src="../../jquery/jquery-1.4.2.min.js"></script>

    <script  type="text/javascript" src="../../jquery/jquery.SPServices-0.5.6.min.js"></script>

    <script type="text/javascript">

    function StartWorkflow(ItemURL, ItemID)

    {

    var loadingImage = 'Loader' + ItemID

    var workflowDiv = 'WorkflowDiv' + ItemID

    //Show our loading image

    document.getElementById(loadingImage).style.visibility = 'visible';

    $().SPServices({

    operation: "StartWorkflow",

    item: ItemURL,

    templateId: "{guid}",

    workflowParameters: "<root />",

    completefunc: function() {

    document.getElementById(workflowDiv).innerHTML = 'Workflow Started';

    }

    });

    }

    </script>

    ---Dataview code---

    <xsl:if test="not(normalize-space(@Single)!='')">
       <div>
       <xsl:attribute name="id">
       <xsl:text>WorkflowDiv</xsl:text>
       <xsl:value-of select="@ID" disable-output-escaping="yes" />
       </xsl:attribute>
       <a href="#">
       <xsl:attribute name="onclick">
      
       <xsl:text>javascript:StartWorkflow(&apos;http://sp2010msf</xsl:text>
       <xsl:value-of select="@FileRef.urlencodeasurl" 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>
      
       Start Workflow</a>
       <img style="visibility:hidden" src="../../jquery/ajax-loader.gif">
       <xsl:attribute name="id">
       <xsl:text>Loader</xsl:text>
       <xsl:value-of select="@ID" disable-output-escaping="yes" />
       </xsl:attribute>
       </img>
       </div>
       </xsl:if>

    Gregg


    MSFT

    21. března 2012 21:12

Všechny reakce

  • Hi Mark,

    We can create a list level workflow, then create a custom action for your custom display form in SharePoint Designer > Click Lists and Libraries > Click your list > Click Custom Action on the ribbon > Display Form ribbon > Select Initiate workflow and select the list workflow.

    And you can also refer to following resources to see the detail steps.
    https://www.nothingbutsharepoint.com/sites/eusp/pages/adding-custom-actions-to-the-ribbon-ui-in-sharepoint-2010-using-sharepoint-designer-2010.aspx
    http://ranaictiu-technicalblog.blogspot.com/2010/06/sharepoint-2010-add-button-to-ribbon.html

    Best regards,
    Emir


    Emir Liu

    TechNet Community Support

    28. února 2012 8:58
  • Thanks for your help,

    It looks like it is not possible to do exactly as I specified - In a list view, have a button in the row for each item and in 1 click auto starts a workflow that changes the Status field.  It looks like I have to use the custom action functionality which adds a button to the ribbon.

    I have tried this and have the following questions:

    a. Is it possible for the workflow to start automatically rather than having to view the initiation screen first?

    b. When I hit Start on the initiation screen which pops up in front of the current window it seems the workflow is started and completes (I know as the item is changed to Resolved) but I do not see an In Progress screen and the initiation popup just stays on the screen.

    Any ideas?

    Thanks,

    Mark 

    28. února 2012 17:55
  • Hello Millard1,

    Thank you for your forum posting. I can provide you with a sample code that you can add to dataview, that will generate a button that will allow you to start a workflow based on clicking that button. This is a sample code and will not work without modification.

    In the Sample code you will need to acquire jquery and spservice from codeplex

    ---Content Editor Web Part code---

    <script type="text/javascript" src="../../jquery/jquery-1.4.2.min.js"></script>

    <script  type="text/javascript" src="../../jquery/jquery.SPServices-0.5.6.min.js"></script>

    <script type="text/javascript">

    function StartWorkflow(ItemURL, ItemID)

    {

    var loadingImage = 'Loader' + ItemID

    var workflowDiv = 'WorkflowDiv' + ItemID

    //Show our loading image

    document.getElementById(loadingImage).style.visibility = 'visible';

    $().SPServices({

    operation: "StartWorkflow",

    item: ItemURL,

    templateId: "{guid}",

    workflowParameters: "<root />",

    completefunc: function() {

    document.getElementById(workflowDiv).innerHTML = 'Workflow Started';

    }

    });

    }

    </script>

    ---Dataview code---

    <xsl:if test="not(normalize-space(@Single)!='')">
       <div>
       <xsl:attribute name="id">
       <xsl:text>WorkflowDiv</xsl:text>
       <xsl:value-of select="@ID" disable-output-escaping="yes" />
       </xsl:attribute>
       <a href="#">
       <xsl:attribute name="onclick">
      
       <xsl:text>javascript:StartWorkflow(&apos;http://sp2010msf</xsl:text>
       <xsl:value-of select="@FileRef.urlencodeasurl" 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>
      
       Start Workflow</a>
       <img style="visibility:hidden" src="../../jquery/ajax-loader.gif">
       <xsl:attribute name="id">
       <xsl:text>Loader</xsl:text>
       <xsl:value-of select="@ID" disable-output-escaping="yes" />
       </xsl:attribute>
       </img>
       </div>
       </xsl:if>

    Gregg


    MSFT

    21. března 2012 21:12
  • Thanks,

    I will give it a go and get back to you.

    Mark  

    28. března 2012 14:53
  • Any updates on this?
    26. srpna 2013 19:02