Saving with JavaScript

  • 1 December 2017
  • 7 replies
  • 21 views

Badge +6

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?


7 replies

Userlevel 5
Badge +14

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. 


Badge +6

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.

Badge +6

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.

Userlevel 5
Badge +14

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? 

Badge +6

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.

Badge +6

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);
}

Badge

Although, this might be an old question. i would like to know where are you using saveAndRedirect() function. is it on client click on the button settings?. i have a similar issue, although i have kept a delay settimeout of 500 milii seconds, the form is not saved in the list and the issue is intermittent. i have a support ticket with Nintex, but they are not helping me with Jquery.

Reply