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

Question

Question

Help Assigning User Task Using Field Value

asked on April 2, 2014 Show version history

I have a couple of questions.

  1. Can you assign a user task based on a fields value?
  2. If so, when using a Windows User does it have to be in the following format "domain\username" or can it just be "username"?

 

We are trying to assign a task to a supervisor based on the user that is filling out the form. We are passing the users name through the querystring to fill out a field with their name and then doing a database lookup for their supervisors username. There username in the database is currently just the "username" without the domain before it.

1 0

Answer

APPROVED ANSWER SELECTED ANSWER
replied on April 3, 2014

If a field is triggering this lookup on your form, it's pretty straightforward to do this. Give the field where the username will go the name field and use the following JavaScript, replacing domain with the appropriate domain name.

 

$(document).ready(function() {
  $('.name').change(function() {
    $('.name input').val('domain\\' + $('.name input').val());
  });
});

 

1 0
replied on September 9, 2014 Show version history

Eric, the jQuery you supplied has been working great. We just added a Field Rule though to show a field if a value from another field is selected. What we are seeing is that the domain\\ value is being added multiple times now. Is there a way to get around this?

 

What we are seeing is similar to this for the value of the field: "domain\domain\domain\SMITCARR"

1 0
replied on September 9, 2014
In the name change function, you probably should check for the domain and only add it if it is missing.
1 0
replied on September 9, 2014 Show version history

Bert, I like your thinking. This is what I've come up with so far, but it does not seem to be working correctly as it does not add the domain at the beginning. Any ideas what I have set incorrect?

$('.name').change(function() {
    if ($('.name input').val:contains('d91_domain\\')) {
     
    } else {
     $('.name input').val('d91_domain\\' + $('.name input').val())
    };
  });

There is a document ready function at the beginning with the correct closing tags.

1 0
replied on September 9, 2014

So the ":contains" filter apparently doesn't work with input fields. Any other ideas of how to compare text?

1 0
replied on September 9, 2014

You could try something like this to see if the domain is already there, or you could only call this code on the initial submission.

$(document).ready(function() {
  $('.name').change(function() {
    if ( $('.name input').val().indexOf('domain\\') == -1 ){
         $('.name input').val('domain\\' + $('.name input').val());      
    }   
  });
});


 

2 0
replied on September 10, 2014

Eric, almost there. We have two fields that have been assigned the class name. With the latest code you posted, domain\ only gets applied to the first one. I would have thought that it would apply to all fields that match that class. Any idea on how to get it to apply to the second field as well?

1 0
replied on September 10, 2014 Show version history

I did some more troubleshooting and I think this is what's happening. The initial field with the name class is populated by a lookup that happens when the form first loads. The second field with the name class is populated from a lookup after a selection is made on the form. It does not appear to add the domain\ once the second field is populated.

 

I'm guessing I need to use the .each() function within the code you supplied?

1 0
replied on September 10, 2014

You need to put this in a repeatable section, that iterates through the rows of the table, and then searches that row for the field in question to modify it.

 

$(document).ready(function() {
  function updateName() {
    $('cf-table-block tbody tr').each(function () {
    if ( $(this).find('.name input').val().indexOf('domain\\') == -1 ){
         $(this).find('.name input').val('domain\\' + $(this).find('.name input').val());      
    }   
    });

  });
$('.name').change(updateName);
});

 

0 0
replied on September 10, 2014

It's not within a table though. They are just two single line fields.

1 0
replied on September 10, 2014 Show version history

 
$(document).ready(function() {
  function updateName() {
    $('.name input').each(function () {
    if ( $(this).val().indexOf('domain\\') == -1 ){
         $(this).val('domain\\' + $(this).val());      
    }   
    });

  });
$('.name').change(updateName);
});

 

Or:

 

$(document).ready(function() {
  $('.name input').change(function() {
    if ( $(this).val().indexOf('domain\\') == -1 ){
         $(this).val('domain\\' + $(this).val());      
    }   
  });
});

Both those should work then (have not tested either though)

1 0
replied on September 10, 2014

The first one did not work, but the second one did. Thank you for your help guys!

1 0
replied on September 10, 2014

I have fixed the first one, I left in the find thing like it was in a table, but have now removed it to allow it to function if you wanted to use it

0 0
replied on September 29, 2014

We just upgraded to 9.2 and the following code you supplied stopped getting applied to the beginning of the field value. Any ideas why it doesn't work anymore?

$('.name').change(function () {
        $('.name input').val('domain\\' + $('.name input').val());
    });

 

1 0
replied on September 29, 2014

It should still be working. Have you modified the code at all? There could be an error.

0 0
replied on September 29, 2014 Show version history

Eric, no, what I posted is what we have, with the exception of the real domain. The username populates from the token, but the domain is never prepended. This affects almost every form we have.

I have tested it and it happens in both IE 11 and the latest version of Chrome.

1 0
replied on September 29, 2014

When I look at the code with Developer Tools in IE11 and I browse to the field in question, I do not see that it has the css class that I have assigned to it of 'name'. Is that the problem? The 'name' class is being applied to the <li> tag before the field.

1 0
replied on September 29, 2014

The issue appears to be that the jquery change event isn't being run when the form is initially loaded and the field is automatically populated via lookup. We can see that this is something that worked in Forms 9.1 and no longer works in Forms 9.2. A bug has been filed and we'll update this thread when more information is available.

1 0
replied on September 29, 2014 Show version history

Hey there, a quick fix for this problem will be changing the line

$(document).ready(function() {
  $('.name').change(function() {
    $('.name input').val('domain\\' + $('.name input').val());
  });
});

to

$(document).ready(function() {
  $('.name').on('change lookup', function() {
    $('.name input').val('domain\\' + $('.name input').val());
  });
});

This should bring back old behavior. Let me know if this at least restores previous functionality for now while we look into it.

0 0
replied on October 22, 2014

How do we alter this new code to apply to two different fields with the .name class? For example, we have two fields with the name class. The first field is changed when right after the form loads by doing a lookup. The second field is changed after some additional information is entered into the form and then a second lookup is performed. The first field is populating correctly, but the second one does not apply the domain\ once the second lookup is performed.

1 0
replied on October 22, 2014 Show version history

The code should work in both cases. There may be a small class difference, so what you can do is the following:

$(document).ready(function() {
  $('.name, .name input').on('change lookup', function() {
    $(this).val('domain\\' + $(this).val());
  });
});

I've added the ".name input" selector to also target the field, which may be because the name class isn't included in the input field (depending on your browser, the <input> element is what should ideally be targeted by this rule. If the <input> element does not have the class ".name", it's possible that only the ".name input" is necessary). I've also changed the inner function to target the changing field. Let me know if this works.

Edited out bolding since it didn't seem to work properly.

0 0
replied on October 22, 2014

That breaks both fields.

1 0
replied on October 22, 2014

I just noticed something weird about the form. When the form first loads, it populates a field called "Supervisors 4x4" and includes the domain\ at the beginning of the value. Another field called "Employee Supervisors 4x4" is also populated with the same value, but after a second the field is cleared. That field should not be getting populated until an employee's name is entered into the form. Looking at the Lookup Rules, I do not see anything that should be filling the "Employee Supervisors 4x4" when the form loads, so I'm not sure what's happening.

1 0
replied on October 22, 2014

Looking at the post history, it may have been a slightly different version you're using. Could you post the snippet you're using? This worked for me (I've added an extra check to prevent the domain from repeating as seen in Kenneth's post):

$(document).ready(function() {
  $('.name input').on('change lookup', function() {
    if($(this).val().indexOf('domain\\') == -1) {
      $(this).val('domain\\' + $(this).val());
    }
  });
});

This seems to work on my forms fine. The old reference code used $('name input') instead of $(this), which will cause every field that has the class "name" to change. This would work fine with one field but not with multiple fields, which I overlooked.

1 0
replied on October 22, 2014 Show version history

That worked perfect! Thank you! Is there a time frame of when the fix for this will be released?

1 0

Replies

replied on April 2, 2014

I figured out that for a Windows User it has to be in the following format to work correctly "domain\username". Since our database only has the username I need to be able to add the domain to the front of the username. Is there a way with JavaScript to do this?

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

Sign in to reply to this post.