AnsweredAssumed Answered

Nintex Forms - Setting DateTime values with Javascript

Question asked by collie96 on Oct 9, 2015
Latest reply on Dec 8, 2016 by aditidas22

Hi all

 

I have three DateTime controls in a Nintex List Form which I want to perform calculations on.

 

In short, I have a Purchase date, which when entered, and in conjunction with a Lookup from a Dropdown List control, I want to update the two other DateTimes with.

 

So, basically, the lookup returned is placed into a calculated value and multiplied by 365 (year values returned from lookup and multiplied to get the number of days to add to a date).  

 

This occurs separately for both the Lifecycle date and Warranty date.

 

I've attempted to use JavaScript to achieve the update of these values, but ultimately can't get the function to work (My JavaScript knowledge is limited, so have made the best attempt I can using other examples I've found).

 

So, the controls: -

 

  • Asset Type (Drop down list. JS Var Name = VarAssetType)
  • Days calc - Lifecycle  (Calculated Field - Performs a lookup based on the Asset Type value selected to return the lifecycle years and is multiplied by 365. JS Var Name = VarLifeFreq)
  • Days calc - Warranty (Calculated Field - Performs a lookup based on the Asset Type value selected to return the warranty years and is multiplied by 365. JS Var Name = VarWarFreq)
  • Purchase Date (DateTime. JS Var Name = VarPurchDate)
  • Lifecycle Date (DateTime. JS Var Name = VarLifeDate)
  • Warranty Date (DateTime. JS Var Name = VarWarDate)

 

And the JavaScript (Note, I've only setup the output for Lifecycle at this stage): -

 

 

/* -------- Nintex control assigned to change event --------- */

var

ctlDTP = NWF$("#" + VarPurchDate);

var ctlCbo = NWF$("#" +

VarLifeFreq);

var ctlCbw = NWF$("#" + VarWarFreq);

var ctlCas = NWF$("#" +

VarAssetType);

 

/* ------ Events ------- */

ctlDTP.bind("change",

function() {CalcDate()});

ctlCbo.bind("change", function()

{CalcDate()});

ctlCbw.bind("change", function()

{CalcDate()});

ctlCas.bind("change", function()

{CalcDate()});

 

function CalcDate()

{

var cctlclife = NWF$('#' +

VarLifeDate);

  // get date from first date picker

  var depart =

ctlDTP.datepicker('getDate');

  depart.setDate(depart.getDate() +

ctlCbo);

 

  // update second date picker

 

cctlclife.datepicker('setDate',depart);

};

 

 

The result, at this point is the LifeCycle control displaying 'NaN/NaN/NaN' which I'm very proud of, but ultimately not what I want .

 

 

Thanks in advance for any assistance.

Outcomes