AnsweredAssumed Answered

Get current value from calculated field

Question asked by akalmar on Jun 19, 2017
Latest reply on Jul 31, 2017 by bstori

Hi,

I've been working on this off and on for weeks and spent a lot of time searching for an answer that would work but so far, I've had no luck!  Hopefully, someone out there can steer me in the right direction.  This is my scenario - I have a form and a workflow.  When a new form is submitted, a workflow is triggered.  When a form is edited (date fields only), a different workflow kicks off.  Now, I know there's a workflow feature that can check previous values vs. new values but I've read that this feature isn't 100% reliable (perhaps this isn't correct?).  Anyways, my goal was to use JavaScript to compare old values vs. new.  This is what a portion of my form looks like:

Form and Formula

 

I've been mostly focusing on the Departure Date first (when I get this right, I'll add change events to the others, as well).  So, to explain - the user opens a form that they have already created because they want to edit the dates.  In this example, the departure date (JavaScript ID = "varEndDateID") is updated and this triggers a change event.  This is what my JS code looks like:

  NWF$("#" + varEndDateID).change(function(){

    var oldDeparture = 'End Date'; //End Date is the item property value
    NWF$("#" + varNewEndDate).trigger('focusout');
    var endDateTime = NWF$("#" + varNewEndDate).val();
    console.log('new end date is: ' + endDateTime);
  });

The new date is supposed to get stored to the variable endDateTime.  But, it always stores the previous date (the one that appears in the calculated field (JavaScript ID = "varNewEndDate") is what appears on the form when it first loads.  I tried making it a global variable but that didn't help.  I've used .trigger('blur'), .trigger('change'), and .trigger('focusout') in an effort to refresh the value in the calculated field but that didn't work, either.  My goal is to take this value and compare it to the original (which I was retrieving by assigning the "End Date" item property to a variable).

 

What am I missing here?  Please help and thanks in advance!

Outcomes