cholslin
Forms Fledgling

Force a Calculated Value Control Update with JavaScript

Jump to solution

Synopsis:

A Nintex Form (SharePoint 2013) has a calculated value control which shows the login name of the current user when they create a new item in a SharePoint list. A block of JavaScript from the Custom JavaScript associated with the form needs to grab this value from the calculated value control on document ready. The ID of the calculated value control is saved in a JavaScript variable called varCalc.

Issue:

The val() of the calculated control is empty when the JavaScript runs on document ready. NWF$('#' + varCalc).val() returns nothing. However, when executed in the browser debugger Console after the page has fully loaded the calculated control is NOT empty.

Attempted Solution:

Calling NWF.FormFiller.Functions.ProcessOnChange(NWF$('#' + varCalc)) does not force the calculated value rule to fire and update the control. Is there a way to get this value?

Actual Code from Custom JavaScript Box in Form Designer:

NWF$(document).ready(function() {
   // Force a process for the calculated value control
   NWF.FormFiller.Functions.ProcessOnChange(NWF$('#' + varCalc));
   NWF$('#' + varSingleLineOfText).val(NWF$('#' + varCalc).val());
});

Is there a way to overcome this issue?  It feels like a race condition between the calculated value handler and the Custom JavaScript.

0 Kudos
Reply
3 Replies
MegaJerk
Automation Master
Automation Master

Re: Force a Calculated Value Control Update with JavaScript

Jump to solution

Instead of using the DOM (or even jquery) event on.ready, you should be using the Nintex Form Event of RegisterAfterReady. 

Example using your code: 

NWF.FormFiller.Events.RegisterAfterReady(function () {
  NWF$('#' + varSingleLineOfText).val(NWF$('#' + varCalc).val());
});

I have left out the ProcessOnChange because in this instance all calculated fields will have been populated with their respective data before this particular event can fire. 

For more information about Nintex Form Events, please see my blog: The Big Event: A Closer Look At Nintex Form Events 

Specifically there is a list under the header "The Order Of Operations" which shows where the native "ready" event fires in the scheme of things that you may find helpful. 

I hope that this solves your problem. 


View solution in original post

Reply
cholslin
Forms Fledgling

Re: Force a Calculated Value Control Update with JavaScript

Jump to solution

A gentleman and a scholar, thank you for the correction of direction. This is precisely the solution I was looking for.

Reply
espradli
Process Pupil

Re: Force a Calculated Value Control Update with JavaScript

Jump to solution

You guys are a lot smarter than I. I am trying to achieve this on a donation form, I don't want the end user to have to click on a "refresh button" or white space for the total calculation to display. Does this code go inside the Nintex form settings Custom JavaScript box? Also, what kind of form variable am I creating. Can you attach a form please so the dumby can figure out how to do this. 

0 Kudos
Reply