Home › Forums › Classic DFFS › Redirect from NewForm to EditForm in DFFS
Tagged: redirect
- This topic has 22 replies, 6 voices, and was last updated 6 years, 9 months ago by Alexander Bautz.
-
AuthorPosts
-
-
October 21, 2015 at 04:10 #8894
Per your article here you mentioned to add more lines for the data object for each field to push to save. I wanted to move the questions to your forum instead of the article.
After adding the code to your existing code, I keep receiving an error on the page (see attached image). I am using all Field Internal names for the data objects and there are no errors in the console only the pop up on the webpage. Not sure if this matters, but all fields beside Title and Office Location are people pickers.
Here is the modified code:
// Save NewForm.apsx and redirect to EditForm.aspx function saveAndRedir(){ setReqID(); var ok = spjs.dffs.check_Mandatory(["Title"]), data = {}, newItem; if(ok){ data.Title = getFieldValue("Title"); data.Requestor = getFieldValue("Requestor"); data.Office_x0020_Location = getFieldValue("Office_x0020_Location"); data.Manager = getFieldValue("Manager"); data.GM = getFieldValue("GM"); data.COO = getFieldValue("COO"); data.CEO = getFieldValue("CEO"); newItem = spjs.utility.addItem( { "listName":_spPageContextInfo.pageListId, "data":data } ); if(newItem.success){ location.href = location.pathname.substring(0,location.pathname.lastIndexOf("/")) + "/EditForm.aspx?ID="+newItem.id; } else{ alert(newItem.errorText); } } }
Thanks in advance!
- This topic was modified 9 years, 1 month ago by soldier1733.
Attachments:
-
October 21, 2015 at 07:12 #8898
This most likely has to do with wrong format of the value in the data object. Which type of fields are the ones you try to update?
Use console.log to look at the data object before the “newItem =…” line – post the output here.
Alexander
-
October 21, 2015 at 17:01 #8901
The fields I am trying to update are People Picker fields for SP2013. Here is the output of the data object:
[object Object]
{
[functions]: ,
CEO: [
0: “Jane Doe”,
length: 1
],
COO: [
0: “John Doe”,
length: 1
],
GM: [
0: “Janice Doe”,
length: 1
],
Manager: [
0: “Jeff Doe”,
length: 1
],
Office_x0020_Location: “Corporate”,
Requestor: [
0: “Janet Doe”,
length: 1
],
Title: “REQ2015-208”
} -
October 21, 2015 at 17:26 #8903
Updating people pickers requires the ID and not the user display name – also the returned value is an array – so it fails on two fronts.
You can try using this code to get the ID of the pp:
data.GM = spjs.utility.userInfo(spjs.utility.getFieldValue({"fin":"GM","key":"loginName"})).ID
Alexander
-
October 21, 2015 at 17:58 #8905
Thank you Alex, that did the trick!!
-
October 23, 2015 at 00:20 #8921
Thanks Alexander! that solved the same issue for me. What about field of type SPFieldDateTime? my field internal name is End_x0020_of_x0020_Week_x0020_Da
-
October 23, 2015 at 00:22 #8923
I only need the date portion
-
October 25, 2015 at 07:58 #8955
The date and time in SharePoint DB is stored in ISO8601 format – October 25 would be entered like this:
2015-10-25 00:00:00
Alexander
-
October 27, 2015 at 17:49 #9027
I meant what is the custom string command I use for a Date field for the redirect to work? I’ve tried several things and nothing seems to work. I keep getting “Invalid date/time value. A date/time field contains invalid data. Please check the value and try again.”
data.End_x0020_of_x0020_Week_x0020_Da = ?
-
October 27, 2015 at 18:20 #9034
You must split the date and reassemble it in the correct format. If your date format is “US” like this: 10/27/2015 you can use something like this:
var d = getFieldValue("TheDateColName").split("/"); data.End_x0020_of_x0020_Week_x0020_Da = d[2]+"-"+d[0]+"-"+d[1]+" 12:00:00";
Alexander
-
March 3, 2016 at 20:37 #10594
Hi Alex, I have used your code for saving and redirecting a form using the code below. It works great except that the required field of “SalesID” no longer seems to be required.
It appears that the code checks the field but there is no alert that forces someone to populate the field. Do you have any suggestions for making the salesID required using this code?
function GoToEdit(){
var ok = spjs.dffs.check_Mandatory([“SalesID”]),
data = {},
newItem,
url;
if(ok){
data.SalesID = getFieldValue(“SalesID”);
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();
}- This reply was modified 8 years, 8 months ago by Penny Kingston.
-
March 4, 2016 at 20:37 #10625
Hi,
I suspect the field “SalesID” is not flagged as required in your list. If this is the case, either set it as required (in DFFS or in the list settings) or add this line of code to the top of your function:spjs.dffs.data.requiredFields.push("SalesID");
Hope this helps,
Alexander -
March 4, 2016 at 20:47 #10629
Hi Alex,
I did have the field set as required but your line of code worked perfectly!
Many thanks! -
March 7, 2016 at 19:56 #10657
Alex,
I am now trying to use the same code on the edit form to save and stay on the edit form. However, using the code above does not work because it tries to create a new item as opposed to saving the existing item. My guess is that I need to modify the newItem line:NewItem = spjs.utility.addItem({“listName”:_spPageContextInfo.pageListId,”data”:data});
I have seen “spjs.utility.addItem” and “spjs.utility.DeleteItem” used in your blogs, do you have a command to edit, save or update an item?
Thanks! -
March 8, 2016 at 19:32 #10684
Hi,
In editform you must use “spjs.utility.updateItem” like this:spjs.utility.updateItem({"listName":_spPageContextInfo.pageListId,"id":spjs.dffs.data.thisItemID,"data":{"Title":"New title value"}});
Alexander
-
March 8, 2016 at 20:03 #10690
Hi again,
This code works and appears to update the “title” field with the pre-defined text “New Title Value”. How could I make this work to update any and all changes to any fields within the form? (There is no way to pre define them.)
Thanks! -
March 8, 2016 at 20:09 #10692
Hi,
It was only an example – just replace thespjs.utility.addItem({...
function with the one from the example, and use the “data” variable instead of the {“Title”:”New title value”} example.
Alexander
-
March 8, 2016 at 20:23 #10694
This is my new code for the “save and edit” button. It is not saving any new or updated data, it is simply refreshing the original data. Thanks again!
function GoToEdit(){
spjs.dffs.data.requiredFields.push(“SalesID”);
data = {};
updateItem = spjs.utility.updateItem({“listName”:_spPageContextInfo.pageListId,”id”:spjs.dffs.data.thisItemID,”data”: data });
if(updateItem.success){location.href = location.href;
}else{alert(updateItem.errorText);} }- This reply was modified 8 years, 8 months ago by Penny Kingston.
-
March 9, 2016 at 20:07 #10709
Hi,
To use this approach you skip the default save method in SharePoint and basically “inject” the data using the “updateItem” function. This means you must add ALL field data (or at least the fields that are changed) to the “data” object.In your code example you pass an empty object, and thus no data is updated.
Alexander
-
June 24, 2016 at 17:29 #12115
Would it be possible to get this redirect and save without close functionality built into the configuration forms?
-
June 29, 2016 at 06:17 #12161
I’m still on the lookout for a good method to handle the redirect in SP 2013, but will hopefully be able to solve this soon. When it comes to “save and stay in form”, I might be able to add it in a later version, but it’s not so easy to support all kind of fields in a consistent way so I cannot promise anything.
Alexander
-
January 30, 2018 at 17:09 #19525
I am having a very hard time getting a lookup field to populate as an additional field.
I’ve pulled it out in console.log and it is a string and it is populated with getFieldValue but i get a generic error “The operation failed because an unexpected error occured”.I pulled the value out and set it as a variable…same result here is my code, any ideas on how to populate a Lookup field?
function saveAndRedir(){
var ok = spjs.dffs.check_Mandatory([“Title”]), data = {}, newItem, url;
var subcat = getFieldValue(“Sub_x0020_Category”);
if(ok){
data.Title = (“Title”);
data.Sub_x0020_Category = subcat;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;
} -
February 1, 2018 at 22:50 #19564
Hi,
Setting a lookup column in code like this requires you to pass the ID of the lookup and not the label. This would be the correct format in your data object:data.Sub_x0020_Category = "123;#;#";
You can try this snippet in your form:
var subcat = jQuery("#dffs_Sub_x0020_Category1").find("select option:selected").val(); data.Sub_x0020_Category = subcat + ";#;#";
Alexander
-
-
AuthorPosts
- You must be logged in to reply to this topic.