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

Get current value from calculated field

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!

0 Kudos
Reply
12 Replies
Workflow Hero

Re: Get current value from calculated field

Hi,

In your calculated field formula, you must use the EndDate value from the control list, not from the item properties list.

Do you understand what i'm talking about ?

Regards.

Accept as Solution Reply
Workflow Hero

Re: Get current value from calculated field

Hi,

My calculated field is using the named control for the EndDate but it's still producing the old date when that date is extracted from the form using JavaScript:

 

Is there anyway I can get the data to be refreshed before extracting it via JavaScript?

Please let me know.  Thanks!

Accept as Solution Reply
Workflow Hero

Re: Get current value from calculated field

And if you execute NWF$("#" + varNewEndDate).val() (with IE10 or IE11) in JavaScript console after modified the DepartureDate, it's the same result ?

Maybe it's a trigger/focus problem.

Regards.

Accept as Solution Reply
Workflow Hero

Re: Get current value from calculated field

Yes, I get the same result when I execute NWF$("#" + varNewEndDate).val() in IE11.  It keeps showing me the previous value rather than the current one.  

Accept as Solution Reply
Workflow Hero

Re: Get current value from calculated field

This works for me on Nintex for Office 365 : 

Regards.

Accept as Solution Reply
Workflow Hero

Re: Get current value from calculated field

Pulling the date directly like that works for me, too, but it only returns the date.  I need the time, as well.  This is why I've been trying to get the date/time in such a roundabout way.  Incidentally, I'm using SharePoint 2013/Nintex 2013 On Premise.  I'm not sure if that makes any difference, but just in case it does, that is the version I'm using!

Accept as Solution Reply
Workflow Hero

Re: Get current value from calculated field

I don't know if it's the same for OnPremise, but this works in Online. I had to change the declaration of my Date field in the SharePoint list and in Nintex Form to display the time.

Regards.

Accept as Solution Reply
Workflow Hero

Re: Get current value from calculated field

I created a calculated field containing the date/time using item properties and one calculated field using the named control date/time value.  When those dates were then logged into the console using jQuery, they were still showing previous dates rather than current. 

Accept as Solution Reply
Workflow Hero

Re: Get current value from calculated field

1. if you only want to know date changed, you do not need to complicate things with hunting for previous value at all.

if your custom change handler is fired you can be sure a change happened.

anyway, you can get new value as follows

NWF$('#'+dtctrl).change(function(evt){
    console.log('new value=' + evt.target.value);
})

2. are you aware of that change handler assigned to date control by a javascript variable is fired only for date input box?

for hours and minutes inputs you will have to attach separate handlers, if you are interested in their changes.

Accept as Solution Reply