Change log
September 23, 2016
I had forgot to add “return false” in the PreSaveAction function – this could result in duplicates being added to the list.
January 05, 2016
Changed the code example to include the “InDlg” attribute if you are in a dialog.
I had forgot to add “return false” in the PreSaveAction function – this could result in duplicates being added to the list.
January 05, 2016
Changed the code example to include the “InDlg” attribute if you are in a dialog.
Here is an alternative solution for redirecting from NewForm to EditForm when using DFFS.
This solution is based on entering NewForm, filling in the Title field, and hitting “Save” to continue in EditForm.
Here is an example on a NewForm
Add this code to the Custom JS
function saveAndRedir(){ var ok = spjs.dffs.check_Mandatory(["Title"]), data = {}, newItem, url; if(ok){ data.Title = getFieldValue("Title"); newItem = spjs.utility.addItem({"listName":_spPageContextInfo.pageListId,"data":data}); if(newItem.success){ url = location.pathname.substring(0,location.pathname.lastIndexOf("/")) + "/EditForm.aspx?ID="+newItem.id; if(GetUrlKeyValue("IsDlg")==="1"){ url += "&IsDlg=1"; } location.href = url; }else{ alert(newItem.errorText); } } } function PreSaveAction(){ saveAndRedir(); return false; }
This is it – test it and let me know how it works out in the Forum.
Best regards,
Alexander
Seems to work brilliantly! 😀
Are you auto-saving before the actual manual save to get the ID (if I’m reading the code correctly)? Does the auto-save trigger new item workflows associate with the list?
Also in the example how are you display that message?
“You must hit “Save” to continue filling in this item”
I tried putting it in a rule but it puts the message on top.
Thanks!
Yes, I use the code to save the item to get the ID. The text below is a “Heading” in DFFS.
I’m fairly sure this will trigger a WF set to run on “new item”.
Alexander
Alexander,
I have implemented your code on small NewForm.aspx with about 6 fields. When the code executes, it only saves the Title field. I am having a hard time to figure out how to have it save all 6 fields before it moves on to the EditForm.aspx page. Any thoughts?
Thank you!
Look at this line in the code:
You’ll need to add one line for each of your fields to push the values into the “data” object.
Alexander
Can this be used on EditForm as well to save the entry but keep the firm open for further changes after saving?
You would get a save conflict when trying to save the original form if you used code to update it and did not refresh the form.
If you however update the form with code, and do a refresh, you would be OK.
Alexander
I also am trying to modify this solution to pass more than just the title field, but continue to get a webpage error upon submit ‘One or more field types are not installed properly. go to the list settings page to delete these fields.’ This error is received after trying to implement your solution of adding additional code: data.Title = getFieldValue(“Title”); My assumption is that is has something to do with the object/array creation.
Can you please provide a more robust example of what the code would look like to pass multiple values from one form to another?
The error indicates that the fieldinternalname you use is wrong.
See this forum post for more examples: https://spjsblog.com/forums/topic/redirect-from-newform-to-editform-in-dffs/
Alexander
This is nice. I had hard time to implement this functionality in SharePoint 2013. You saved me. 🙂
Sunil
Do you have a way of using this go from the EditForm.aspx to DispForm.aspx?
Currently not – other than use the same approach as here and updating the list item with code instead of saving normally, but this will be tricky in large forms as you must collect all changed values and format them correct based on the column type.
I’m on the look for a good redirect method in SP2013, but still have not been able to figure this one out.
Alexander
Works great except for a date field. I receive the following error when adding a Date field to the code:
Invalid Date/time value.
A date/time field contains invalide data. Please check the value and try again.
The field is configured as a Date only field with no further validation rules.
Hi,
Sorry for the delay – you find the answer in this post (linked in a comment above): https://spjsblog.com/forums/topic/redirect-from-newform-to-editform-in-dffs/
Alexander
Thank you for your help (and patience) as always!
Hi there
When trying this new method, I end up with the left hand navigation included as part of the modal dialog for the display form. Any ideas what I have done wrong?
Regards
Gerry
I have updated the code example.
Alexander