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

Question

Question

Set a Field to the Current User

asked on January 19, 2018

We capture names and dates for electronic signatures. We also allow folks to reassign tasks. Because of that, for each form, I have fields that will capture current user and current username:

The javascript then takes the info and copies it to the corresponding field:

$(document).ready(function(){

//Change to Current User
  var assignedUsername = $('.peUsername input').val(''); //Clear value in username field
  var assignedUser = $('.pe input').val(''); //Clear variable
  var currentUser = $('.currentPEUser input').val(); //Get variable
  var currentUsername = $('.currentPEUsername input').val(); //Get variable
  $(assignedUser).prop("readonly", false);
  $(assignedUser).val(currentUser).change();
  $(assignedUser).prop("readonly", true);
  $(assignedUsername).val(currentUsername).change();

});  //close document.ready

While the user has the form open, it does change the name ... however, it reverts back to what it was before when it goes to the next form. Any ideas why?

0 0

Answer

SELECTED ANSWER
replied on January 19, 2018

OK, went with a totally different solution that I found here:

https://answers.laserfiche.com/questions/78406/Using-currentuser-variable-in-Forms

I set up a lookup rule:

More reliable and easier to implement!

1 0

Replies

replied on June 16, 2020

Although this is old post, but I think I should post a better solution for this so that anyone reaching this looking for an answer may find this useful; The best way to keep a (dynamic) token as default value and keep that field refreshed on each form is to add a field rule that hides the field and use "Ignore the data when the field/section/page is hidden" option. This way it will not save the default value when submitted and the next time it will get an updated token value (for example current user).

If you want to show the field, you'd add another field and have it copy the value using advance/calculation setting.

3 0
replied on January 19, 2018

I think what's happening is that the task gets rejected and goes back through only remembering the previous info and not keeping the new info. Is there a way I can set the current user and current username to their corresponding fields through javascript?

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

Sign in to reply to this post.