Question

Hello I really need help with this... , I am using Sharepoint 2007.

I have the 'collect data from user' action in a workflow - which generates a custom form within the workflow folder.

The form uses a DataFormWebPart which contains xsl stylesheet. It has a 'Complete Task' button as below:

<td><input type="button" name="btnMarkSubmited" value="Complete Task" onclick="javascript: {ddwrt:GenFireServerEvent(concat('__update;__workflowTaskComplete={',ddwrt:EcmaScriptEncode(string($Id)),'*',ddwrt:EcmaScriptEncode($ListName),'};__commit;__redirectsource;__redirectToList={',ddwrt:EcmaScriptEncode($ListName),'};'))}"></input></td>

I need to add javascript within the DataFormWebPart so I can update another form field when the user clicks the 'Complete Task' button.

I have tried adding a content editor webpart and used jquery to update a a form field value when the button is clicked as such

$(document).ready(function (){
$("input[type=button][value='Complete Task']").click(function(){
$("input[type=checkbox]").attr("checked", true);
});

This changes the form field succesfully but does not save to the list when the form submits. I have also tried to call a javascript function from within the onclick but it does not find the function when placed in the content editor webpart (or within placeholdermain template).

Please could someone give me any ideas on this? I have pasted the form's DataFormWebPart below for reference:

Many Thanks!

<WebPartPages:DataFormWebPart runat="server" IsIncluded="True" FrameType="None" NoDefaultStyle="TRUE" ViewFlag="0" Title="{BC399A4C-0DB0-4BE7-9542-CD8001CC2902}" __markuptype="vsattributemarkup" __WebPartId="{9A02BCE0-AAE3-4A75-A736-8789BF8C9AF9}" id="TaskForm" pagesize="1" datasourceid="SPDataSource2">
    <DataSources>
        <SharePoint:SPDataSource runat="server" DataSourceMode="ListItem" UseInternalName="true" selectcommand="&lt;View&gt;&lt;ViewFields&gt;&lt;FieldRef Name=&quot;ID&quot;/&gt;&lt;FieldRef Name=&quot;PermMask&quot;/&gt;&lt;/ViewFields&gt;&lt;/View&gt;" id="SPDataSource2"><SelectParameters><WebPartPages:DataFormParameter Name="ListID" ParameterKey="ListID" PropertyName="ParameterValues" DefaultValue="{BC399A4C-0DB0-4BE7-9542-CD8001CC2902}"/><WebPartPages:DataFormParameter Name="listitemid" ParameterKey="listitemid" PropertyName="ParameterValues"/><asp:Parameter Name="StartRowIndex" DefaultValue="0"/><asp:Parameter Name="nextpagedata" DefaultValue="0"/><asp:Parameter Name="MaximumRows" DefaultValue="1"/></SelectParameters><DeleteParameters><WebPartPages:DataFormParameter Name="ListID" ParameterKey="ListID" PropertyName="ParameterValues" DefaultValue="{BC399A4C-0DB0-4BE7-9542-CD8001CC2902}"/></DeleteParameters><InsertParameters><WebPartPages:DataFormParameter Name="ListID" ParameterKey="ListID" PropertyName="ParameterValues" DefaultValue="{BC399A4C-0DB0-4BE7-9542-CD8001CC2902}"/></InsertParameters><UpdateParameters><WebPartPages:DataFormParameter Name="ListID" ParameterKey="ListID" PropertyName="ParameterValues" DefaultValue="{BC399A4C-0DB0-4BE7-9542-CD8001CC2902}"/></UpdateParameters></SharePoint:SPDataSource>
    </DataSources>
    <ParameterBindings>
        <ParameterBinding Name="dvt_apos" Location="Postback;Connection"/>
        <ParameterBinding Name="UserID" Location="CAMLVariable" DefaultValue="CurrentUserName"/>
        <ParameterBinding Name="Today" Location="CAMLVariable" DefaultValue="CurrentDate"/>
        <ParameterBinding Name="dvt_startposition" Location="Postback" DefaultValue=""/>
        <ParameterBinding Name="dvt_firstrow" Location="Postback;Connection"/>
        <ParameterBinding Name="dvt_nextpagedata" Location="Postback;Connection"/>
        <ParameterBinding Name="ListID" Location="None" DefaultValue="{BC399A4C-0DB0-4BE7-9542-CD8001CC2902}"/>
        <ParameterBinding Name="listitemid" Location="QueryString(ID)" DefaultValue=""/>
        <ParameterBinding Name="Id" Location="QueryString(ID)" DefaultValue="0"/>
        <ParameterBinding Name="ListName" Location="QueryString(List)" DefaultValue=""/>
    </ParameterBindings>
    <datafields>@Title,Title;@Priority,Priority;@Status,Status;@PercentComplete,% Complete;@AssignedTo,Assigned To;@TaskGroup,Task Group;@Body,Description;@StartDate,Start Date;@DueDate,Due Date;@Holiday_x0020_Request_x0020_Appr,Holiday Request Approve Status;@Complete,Complete;@HolidayRequestRefID,HolidayRequestRefID;@WorkflowLink,Link;@OffsiteParticipant,External Participant;@OffsiteParticipantReason,External Participant Reason;@WorkflowOutcome,Outcome;@WorkflowName,Workflow Name;@ContentType,Content Type;@Related_x0020_request_x0020_item,Related request item;@Holiday_x0020_Request_x0020_Stat,Holiday Request Status;@Comments1,Comments;@TaskCrea,Task Created;@TaskModi,Task Modified;@Reviewed,Reviewed;@TaskIDNum,TaskIDNum;@StatusUpdate,StatusUpdate;@ID,ID;@Modified,Modified;@Created,Created;@Author,Created By;@Editor,Modified By;@_UIVersionString,Version;@Attachments,Attachments;@File_x0020_Type,File Type;@FileLeafRef,Name (for use in forms);@FileDirRef,Path;@FSObjType,Item Type;@_HasCopyDestinations,Has Copy Destinations;@_CopySource,Copy Source;@ContentTypeId,Content Type ID;@_ModerationStatus,Approval Status;@_UIVersion,UI Version;@Created_x0020_Date,Created;@FileRef,URL Path;</datafields>
    <XSL>
<xsl:stylesheet xmlns:x="http://www.w3.org/2001/XMLSchema" xmlns:dsp="http://schemas.microsoft.com/sharepoint/dsp" version="1.0" exclude-result-prefixes="xsl msxsl ddwrt" xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime" xmlns:asp="http://schemas.microsoft.com/ASPNET/20" xmlns:__designer="http://schemas.microsoft.com/WebParts/v2/DataView/designer" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:SharePoint="Microsoft.SharePoint.WebControls" xmlns:ddwrt2="urn:frontpage:internal">



 <xsl:output method="html" indent="no"/>
    <xsl:decimal-format NaN=""/>
    <xsl:param name="dvt_apos">&apos;</xsl:param>
    <xsl:param name="dvt_firstrow">1</xsl:param>
    <xsl:param name="dvt_nextpagedata" />
    <xsl:param name="ListID">{BC399A4C-0DB0-4BE7-9542-CD8001CC2902}</xsl:param>
    <xsl:param name="listitemid" />
    <xsl:param name="Id">0</xsl:param>
    <xsl:param name="ListName" />   
    <xsl:variable name="dvt_1_automode">0</xsl:variable>




    <xsl:template match="/">
        <xsl:call-template name="dvt_1"/>
    </xsl:template>
    <xsl:template name="dvt_1">
        <xsl:variable name="dvt_StyleName">RepForm3</xsl:variable>
        <xsl:variable name="Rows" select="/dsQueryResponse/Rows/Row"/>
        <xsl:variable name="dvt_RowCount" select="count($Rows)" />
        <xsl:variable name="RowLimit" select="1" />
        <xsl:variable name="FirstRow" select="$dvt_firstrow" />
        <xsl:variable name="LastRow" select="$FirstRow + $dvt_RowCount - 1" />
        <xsl:variable name="IsEmpty" select="$dvt_RowCount = 0" />
        <xsl:call-template name="dvt_1.header">
            <xsl:with-param name="Rows" select="$Rows" />
        </xsl:call-template>
        <table border="0" width="100%">
            <xsl:call-template name="dvt_1.body">
                <xsl:with-param name="Rows" select="$Rows"/>
                <xsl:with-param name="FirstRow" select="1" />
                <xsl:with-param name="LastRow" select="$dvt_RowCount" />
            </xsl:call-template>
        </table>
        <xsl:call-template name="dvt_1.commandfooter">
            <xsl:with-param name="FirstRow" select="$FirstRow" />
            <xsl:with-param name="LastRow" select="$LastRow" />
            <xsl:with-param name="RowLimit" select="$RowLimit" />
            <xsl:with-param name="dvt_RowCount" select="$dvt_RowCount" />
            <xsl:with-param name="RealLastRow" select="number(ddwrt:NameChanged('',-100))" />
        </xsl:call-template>
    </xsl:template>
    <xsl:template name="dvt_1.body">
        <xsl:param name="Rows"/>
        <xsl:param name="FirstRow" />
        <xsl:param name="LastRow" />
        <xsl:for-each select="$Rows">
            <xsl:variable name="dvt_KeepItemsTogether" select="false()" />
            <xsl:variable name="dvt_HideGroupDetail" select="false()" />
            <xsl:if test="(position() &gt;= $FirstRow and position() &lt;= $LastRow) or $dvt_KeepItemsTogether">
                <xsl:if test="not($dvt_HideGroupDetail)" ddwrt:cf_ignore="1">
                    <xsl:call-template name="dvt_1.rowedit">
                        <xsl:with-param name="Pos" select="concat('_', position())" />
                    </xsl:call-template>
                </xsl:if>
            </xsl:if>
        </xsl:for-each>

    </xsl:template>
    <xsl:template name="dvt_1.rowedit">
        <xsl:param name="Pos" />
        <tr>
            <td>
                <table border="0" cellspacing="0" width="100%"><tr><td class="ms-formlabel" valign="top" nowrap="true" width="25%"><b>Title:</b></td><td class="ms-formbody" valign="top" width="75%">Collect approval status<br></br><br></br></td></tr>
                    <tr>
                        <td width="25%" class="ms-formlabel">
                            <b>Holiday Request Status:</b>
                        </td>
                        <td width="75%" class="ms-formbody">
                            <SharePoint:FormField runat="server" id="ff1{$Pos}" ControlMode="Edit" FieldName="Holiday_x0020_Request_x0020_Stat" __designer:bind="{ddwrt:DataBind('u',concat('ff1',$Pos),'Value','ValueChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@Holiday_x0020_Request_x0020_Stat')}"/>
                            <SharePoint:FieldDescription runat="server" id="ff1description{$Pos}" FieldName="Holiday_x0020_Request_x0020_Stat" ControlMode="Edit"/>
                        </td>
                    </tr>
                    <tr>
                        <td width="25%" class="ms-formlabel">
                            <b>Comments:</b>
                        </td>
                        <td width="75%" class="ms-formbody">
                            <SharePoint:FormField runat="server" id="ff2{$Pos}" ControlMode="Edit" FieldName="Comments1" __designer:bind="{ddwrt:DataBind('u',concat('ff2',$Pos),'Value','ValueChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@Comments1')}"/>
                            <SharePoint:FieldDescription runat="server" id="ff2description{$Pos}" FieldName="Comments1" ControlMode="Edit"/>
                        </td>
                    </tr>
                    <tr >
                        <td width="25%" class="ms-formlabel">
                            <b>Reviewed:</b>
                        </td>
                        <td width="75%" class="ms-formbody">
                            <SharePoint:FormField runat="server" id="ff3{$Pos}" ControlMode="Edit" FieldName="Reviewed" />
                            <SharePoint:FieldDescription runat="server" id="ff3description{$Pos}" FieldName="Reviewed" ControlMode="Edit"/>
                        </td>
                    </tr>
                    <tr style="display:none">
                        <td width="25%" class="ms-formlabel">
                            <b>TaskIDNum:</b>
                        </td>
                        <td width="75%" class="ms-formbody">
                            <SharePoint:FormField runat="server" id="ff4{$Pos}" ControlMode="Edit" FieldName="TaskIDNum" __designer:bind="{ddwrt:DataBind('u',concat('ff4',$Pos),'Value','ValueChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@TaskIDNum')}"/>
                            <SharePoint:FieldDescription runat="server" id="ff4description{$Pos}" FieldName="TaskIDNum" ControlMode="Edit"/>
                        </td>
                    </tr>
                    <xsl:if test="$dvt_1_automode = '1'" ddwrt:cf_ignore="1">
                        <tr>
                            <td colspan="99" class="ms-vb">
                                <span ddwrt:amkeyfield="ID" ddwrt:amkeyvalue="ddwrt:EscapeDelims(string(@ID))" ddwrt:ammode="edit"></span>
                            </td>
                        </tr>
                    </xsl:if>
                <tr><td class="ms-formlabel" valign="top" nowrap="true" width="25%"><b>Related list item:</b></td><td class="ms-formbody" valign="top" width="75%"><a href="{substring-before(@WorkflowLink, ', ')}"><xsl:value-of select="substring-after(@WorkflowLink, ', ')"></xsl:value-of></a></td></tr></table>
            </td>
        </tr>

    </xsl:template>
    <xsl:template name="dvt_1.commandfooter">
        <xsl:param name="FirstRow" />
        <xsl:param name="LastRow" />
        <xsl:param name="RowLimit" />
        <xsl:param name="dvt_RowCount" />
        <xsl:param name="RealLastRow" />
        <table cellspacing="0" cellpadding="4" border="0" width="100%">
            <tr>
                <xsl:call-template name="dvt_1.formactions" />
                <xsl:if test="$FirstRow &gt; 1 or $dvt_nextpagedata"></xsl:if>
            </tr>
        </table>
    </xsl:template>
    <xsl:template name="dvt_1.formactions">
        <td nowrap="nowrap" class="ms-vb">
            <input type="button" value="Save Draft" name="btnSave" onclick="javascript: {ddwrt:GenFireServerEvent(concat('__update;__commit;__redirectsource;__redirectToList={',ddwrt:EcmaScriptEncode($ListName),'};'))}" />
        </td><td><input type="button" name="btnMarkSubmited" value="Complete Task" onclick="javascript: {ddwrt:GenFireServerEvent(concat('__update;__workflowTaskComplete={',ddwrt:EcmaScriptEncode(string($Id)),'*',ddwrt:EcmaScriptEncode($ListName),'};__commit;__redirectsource;__redirectToList={',ddwrt:EcmaScriptEncode($ListName),'};'))}"></input></td>
        <td nowrap="nowrap" class="ms-vb" width="99%">
            <input type="button" value="Cancel" name="btnCancel" onclick="javascript: {ddwrt:GenFireServerEvent(concat('__cancel;__redirectsource;__redirectToList={',ddwrt:EcmaScriptEncode($ListName),'};'))}" />
        </td></xsl:template>
    <xsl:template name="dvt_1.header">
        <xsl:param name="Rows" />
        <table cellSpacing="0" cellPadding="4" border="0" width="100%">
            <tr>
                <td class="ms-vb">
                    <xsl:text disable-output-escaping="yes" ddwrt:nbsp-preserve="yes">&amp;nbsp;</xsl:text>
                </td>
            </tr>
        </table>
    </xsl:template>
</xsl:stylesheet>   </XSL>
</WebPartPages:DataFormWebPart>
Was it helpful?

Solution

Would I be right in thinking that the Workflow action triggered by the button's OnClick is triggered before your jQuery click event? This would mean the form data is captured and the list updated before the jQuery updates your form field...

In which case, try updating the form field from within the Workflow itself rather than the jQuery?

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