New Form Keep Values

I have a request that they want to be able to create new records but keep certain fields populated form the previous saved one. Is it possible to have 2 buttons on the form, one to save record and go back to list (normal operation) and one to save item and then re-open the same "New form" with certain fields maintaining their value?

Dear @IT.Joe,
Use the following code in button's Click property to save values and redirect to New form again:

localStorage.setItem('form-data', JSON.stringify(fd.data()));

fd.spSaved(function(result) {
    var listId = fd.spFormCtx.ListAttributes.Id;

    //replace "https://domain.sharepoint.com/sites/sitename/subsite" with path to your site
    //PageType=8 means New Form, no itemId is required
    result.RedirectUrl =
        "https://domain.sharepoint.com/sites/sitename/subsite/_layouts/15/listform.aspx?PageType=8&ListId="
        + listId;
});

fd.save();

And the following code on New form in JS editor to parse it:

fd.spRendered(function(){
    var data = JSON.parse(localStorage.getItem('form-data'));
    if(data){
      fd.data(data);
      localStorage.removeItem('form-data');
    }
});

Hi Nikita,

This appears to work, however the date fields do not save using the values brought through from local storage. Date fields error saying 'you must specify a valid date within the range of 01/01/1900 and 31/12/8900 - but the dates are valid!

Any ideas?

Kind regards

Andy

Hello @abolam,

You need to convert the string to a valid date format. Please try out this code:

fd.spRendered(function(){
    var data = JSON.parse(localStorage.getItem('form-data'));
    if(data){
      fd.data(data);
      fd.field('Date').value = new Date(fd.field('Date').value)
      localStorage.removeItem('form-data');
    }
});

Replace Date with the field internal name.