cancel
Showing results for 
Search instead for 
Did you mean: 
Workflow Hero

Saving with JavaScript

Jump to solution

Hi!

I try to save a form and redirect it to another page.

The save button is hidden with css ( .saveButton {visibility: hidden;}) and I use a javascript button to fire the function.

The redirection is working, but the list item isnt saved.

(I dont use the built in redirect as I would like to extend the function with else if logic and different links)

This is the code:

function saveAndRedirect() {
  NWF$('.saveButton').click();
  window.location.replace('https://www.google.com');
}

I added a "test" code to the hidden save button client click if it is clicked or not by the function and it is clicked as the alert is popping up correctly!

Client click: NWF$(document).ready(function(){alert('Save Clicked');});

My conclusion is that the code is good so far as the function is clicking the save button and the page is redirected, BUT why it is not saved to the list? Is there an additional code to actually save the item?

Labels: (2)
Tags (1)
0 Kudos
Reply
6 Replies
Workflow Hero

Re: Saving with JavaScript

Jump to solution

Could you not just simply use the redirect that was introduced natively to the Button control? 

Lucky You, there's New Form Features! 

I do not recommend going down the terrible path of manually submitting the form information back to SharePoint if at all possible. 


Reply
Workflow Hero

Re: Saving with JavaScript

Jump to solution

Hi Marples,

Actually I would like to build a logic for the re-directing based on a drop down value, so there will be different re-direct links.

My Nintex Form dont have the future you linked.

0 Kudos
Reply
Workflow Hero

Re: Saving with JavaScript

Jump to solution

What I see in other forums that for someone the same code works, and the list item is saved, but for some its not.

I am wondering if there is other requirement, maybe different Nintex or SharePoint version for this to work.

0 Kudos
Reply
Workflow Hero

Re: Saving with JavaScript

Jump to solution

Perhaps, you're right. 

The release for the redirect on button stuff was 

Product version: 2.10.0.0
Release date: 8th March 2017

(for On Premise 2013) 

Which version are you running? 

0 Kudos
Reply
Workflow Hero

Re: Saving with JavaScript

Jump to solution

We have SP 2013 on Premise and Nintex Forms 2013 version 2.7.0.0

The redirecting with JS works, only the saving is not.

0 Kudos
Reply
Workflow Hero

Re: Saving with JavaScript

Jump to solution

OK, I figured out why the saving not works.

The problem is that the 2 code runs simultaneously and redirecting the page is quicker than saving with .click()

It can be fixed 2 ways:

1. Open the redirect page in a new tab:

function saveAndRedirect() {
  NWF$('.saveButton').click();
  window.open('https://www.google.com', '_blank');
}

2. Use setTimeout to add a time delay for the redirection:

   

function saveAndRedirect() {
  NWF$('.saveButton').click();

  setTimeout(function(){
  window.location.replace('https://www.google.com');

}, 100);
}

Reply