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

Question

Question

Current User info in Form's Final Version

asked on May 5, 2020 Show version history

Working with Time Sheets, we wanted to add an alert if the person entering the data into the form is not the person whose time sheet it is.

 

On the form, I have:

A field named CurrentUserADUsername that defaults to: {/_currentuser}

A field named EmployeeADUsername that pulls in the employee's AD username from a DB Lookup

A field named CompareValues with this calculation: =IF(CurrentUserADUsername=EmployeeADUsername,"SAME","DIFFERENT")

An HTML field which contains the following:

"Data on this form was entered by {/dataset/_initiator_displayname} on {/dataset/employee_name}'s behalf."

 

And I'm using the following Javascript (where the HTML field is q1 and the CompareValues field is q2) to show/hide that HTML:

$(document).ready(function () {

    $(document).on('lookup change', hideotheruserfunction);
    function hideotheruserfunction() {

    if($('#q1 input').val() == "SAME") {
    $('#q2').hide();

    } else {
    $('#q2').show(); 

        }
      }
    });
 

This all works perfectly: the HTML block displays if the current user name (on the input form) is not the same as the employee name.  "Data on this form was entered by Cookie Monster on Big Bird's behalf."  

 

Here's my problem: when the form becomes final, there is no longer a "Current User," so there is always a mismatch (username at that point becomes "Anonymous User"), and every form is showing the HTML with the Initiator Name and the Employee Name, like: "Data on this form was entered by Cookie Monster on Cookie Monster's behalf." 

**Looks like "Anonymous User" isn't the only problem here; something else must be happening when the form enters a Read Only state that causes this HTML to be unhidden. ???

 

I searched this support site, and found some mention of this, but the responses weren't anything I could translate to fit my specific situation. Much earlier today, I had the idea to match on Initiator's UserID instead of Current User's UserID, but that field wasn't populating, so I didn't go down that path. 

 

It's not strictly necessary for the HTML to display in the final resting version of the form. Can I maybe modify this calculation to take into account the "Anonymous User" (would want to return SAME in this case so the HTML would not display).

=IF(CurrentUserADUsername=EmployeeADUsername,"SAME","DIFFERENT")

 

I hope this all makes sense. Thank you in advance for any help you can provide!

0 0

Answer

SELECTED ANSWER
replied on May 6, 2020

Hi Jennifer,

Assuming you're hiding CurrentUserADUsername with field rules, is it set to "Save when hidden"? This would ensure it keeps the initial value of the first current user.

Alternatively, you could try adding in a check in the JavaScript that hides it if the current user field is "Anonymous User".

 

Side note, your JavaScript to hide the HTML field could easily be a field rule instead.

0 0
replied on May 6, 2020

I am using a Field Rule to hide the CurrentUserADUsername field and it is checked to Save when hidden - this apparently doesn't work when the form is converted into its final, read-only version.

 

I don't believe HTML fields can be hidden using Field Rules, since the field doesn't have a name or variable name, but maybe there's a method I'm not familiar with.

 

I will try accounting for "Anonymous User" in the Javascript, but I mostly just stumble my way through using JS so I'd be grateful if anyone can assist with that piece.

 

Thank you for your reply!

0 0
replied on May 6, 2020 Show version history

HTML fields can definitely be hidden with field rules. They usually appear at the top of the list as whatever the HTML code is ("<p>test html>/p>" for example). However if you're using JavaScript to check for Anonymous User then you might as well keep it as-is.

Give this a try, where q3 is the CurrentUserADUsername field:

$(document).ready(function () {
  $(document).on('lookup change', hideotheruserfunction);
  function hideotheruserfunction() {
    if($('#q1 input').val() == "SAME" && $('#q3 input').val().toLowerCase() != "anonymous user") {
      $('#q2').hide();
    }
    else {
      $('#q2').show();
    }
  }
});

 

1 0
replied on May 6, 2020

That code does work, thank you!

Unfortunately, the problem isn't resolved. I think something else is happening when the form becomes Read Only that causes that HTML block to be unhidden.

0 0

Replies

replied on May 6, 2020

I just tried this using a Lookup Rule instead of JS, and that does work. Thank you so much for all of your time!  As usual, I was making things harder than they needed to be.  smiley

1 0
replied on May 6, 2020 Show version history

I tried setting both conditions in my Javascript to .hide, like this:

$(document).ready(function () {

    $(document).on('lookup change', hideotheruserfunction);
    function hideotheruserfunction() {

    if($('#q1 input').val() == "SAME") {
    $('#q2').hide();

    } else {
    $('#q2').hide(); 

        }
      }
    });

 

...and the HTML (field 2 in this example) block is still being displayed on the final, saved copy of the form (found under "Completed Tasks"). 

So the JS isn't running at all when this copy of the form is generated.

I think that's the real issue here.  Any ideas?

 

(editing to add that the JS to show/hide does work while the task is in process)

0 0
replied on May 6, 2020

Oh hang on, it might be because there's no longer a lookup rule being completed to trigger it. Try this:

$(document).ready(function() {
  hideotheruserfunction();
});
$(document).on('lookup change', hideotheruserfunction);
function hideotheruserfunction() {
  if($('#q1 input').val() == "SAME" && $('#q3 input').val().toLowerCase() != "anonymous user") {
    $('#q2').hide();
  }
  else {
    $('#q2').show();
  }
};

 

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

Sign in to reply to this post.