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

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
2 Replies
Highlighted
Workflow Hero

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. 


Reply
Workflow Hero

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.

0 Kudos
Reply