Save As draft in SharePoint 2013 custom list form
-
08-02-2021 - |
Question
I want to have two separate buttons in SharePoint 2013 Custom List Form. One is Save As Draft and the other is Submit. I have a choice field with column name Status with values Draft, Submitted, Approved, Rejected. The draft should only be seen by Creator.
<td class="ms-toolbar" nowrap="nowrap">
<SharePoint:SaveButton runat="server" ControlMode="New" id="savebutton3" Text="Save As Draft"/>
</td>
<td class="ms-toolbar" nowrap="nowrap">
<SharePoint:SaveButton runat="server" ControlMode="New" id="savebutton1"/>
</td>
How can I set values of status column based on button click like if I clicked Save As Draft status should be Draft and when Clicked on Submit value of status column should be submitted?
Solution
- Set "Submitted" as default value of "Status" field
Paste
<td> <input name="saveAsDraft" type="button" value="Save as draft" onclick="saveAsDraft();"/> </td>
instead of
<td class="ms-toolbar" nowrap="nowrap"> <SharePoint:SaveButton runat="server" ControlMode="New" id="savebutton3" Text="Save As Draft"/> </td>
Write JS function "saveAsDraft()". Code:
function saveAsDraft(){ var t = $("select[title='Status']"); t.val('Draft'); $("input[value='Save']").click(); }
Place JS script on the page
OTHER TIPS
- Add two buttons into your list form
- Add js file into form
- Trigger the Workflow to assign permission based on the dropdown value
HTML Example
<td>
<input name="saveAsDraft" type="button" value="Save as draft" id="SaveAsDraft();"/>
</td>
<td>
<input name="Submit Data" type="button" value="Submit Data" id="SubmitData();"/>
</td>
JS File Example
$(document).ready(function (){ $('#SaveAsDraft').click(function (){ $('#dropdown option').val('SaveAsDraft'); PreSaveUpdates(); }); $('#SubmitData').click(function (){ $('#dropdown option').val('Submitted'); PreSaveUpdates(); }); }); function PreSaveUpdates(){ return true; }
Note: If you are using "$(document).ready" in your code, make sure PreSaveAction function is written outside this block, as in above code or else PreSaveAction method will not be called.
Workflow Steps:
- Trigger the WF when an item created and modified
- Based on the dropdown value check the condition
- Assign Item level permission to created by user, if the dropdown value is "Draft".