You are viewing limited content. For full access, please sign in.

Question

Question

Update to variable using javascript not persisting during process

asked on November 17, 2014

I have a process with several forms. The second form in the process is a status form, showing participants where their form is in the approval process. The process has a loop that sends the form back to the employee, if it's denied by AP and sends AP a status form to help them keep track of what's currently outstanding. However, I only want the status form to be sent back to AP if they haven't already been sent one during the process, otherwise, if they reject the same employee's form more than once, they'll have multiple status forms in their queue for the same process.

So, I'm using a field and javascript to implement a counter that increments every time AP gets a status form during the process. The counter starts at 0. The process I created looks to see if the variable associated with the field is set to 0. If it is, AP receives the status form. If the field/variable is great than 0, AP won't receive the status form.

From a logic standpoint, this seems like it should work. However, I'm finding that even though I'm saving the incremented value back to the field, the new field value isn't retained. I can see that it's been set the first time the form is sent to AP. The second and subsequent times the form is sent to AP, the field value remains the same.

Is there something I need to do in javascript to commit the new value to the field? I've included my code below:

 

$(document).ready(function () {
 
    $('#q192').on('change lookup', changeAPSteps);
    
      function changeAPSteps() {
        var isap = $('#q192 input').val();

        if ( isap === "yes") {
            var apstep = parseNumber($('#q193 input').val());
            var sum = apstep + 1;
    
              // increment APStep field value (used for process to determine whether or
              // not to send AP a status form (if > 1, don't send status form because they
              // already got one)
            $('#q193 input').val(sum);
        }
      }    
 
    function parseNumber(n) {
        var f = parseFloat(n); //Convert to float number.
        return isNaN(f) ? 0 : f; //treat invalid input as 0;
    }
});

 

 

Thanks for any help you can give me!

0 0

Replies

replied on November 17, 2014

I think it's because you are updating based on the change of a field, which already has the value set the same, since it's rejected.

 

So, maybe you change it to be performed on page load? 

 

Also, what's with the two fields being used for getting the value and storing the value? Why not retrieve, increment and then store back to the same field? 

0 0
replied on November 17, 2014

I can't change it to increment on load, because a db lookup is done to see if the form was sent to an AP user.

One of the fields (192) is populated with a value from a database table, if the user is someone  in the AP department. If it's an AP user, the number is incremented. Otherwise, it's not. It's only using field 193 to get the value from and store the new, incremented value. And I'm only testing as an AP user right now.

It assigns the "apstep" variable the value from field 193, increments it by 1, storing that incremented value in the "sum" variable. Then it assigns whatever the value of "sum" is back to field 193. It just doesn't seem to save it in that field once the process continues.

However, I think I just figured out why it's not working. If the user doesn't open and select an action on the form, the values aren't saved in the fields. So, I need to put that javascript on another form in the process. One that has to have an action taken on it in order for the process to continue.

Thanks for the response, though!!

0 0
replied on November 18, 2014

Is the field read-only by chance?

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.