How person field works?

Hi,

Probably I've found a bug.
In spRendered I call a function which reads user profile and writes persons manager to extra field. Quite normal and popular situation.
Some users has a problem with it because system displays different peron as their manager.
The situation happens when you have persons with similar logins and display names. For example "DOMAIN\Adam.Dhont" with display name "Adam Dhont (Warsaw)" and "DOMAIN\Adam.Dhont1" and display name "Adam Dhont (Berlin)".

case 'Manager':
					fd.field('personUserManager').value = props[i].Value;

The code above will write DOMAIN\Adam.Dhont as login name but Adam Dhont (Berlin) in fd.field('personUserManager').widget.text().

Any ideas how to go around with it?

Hello @Marcin,

Let me clarify a few things.

Is the issue with the incorrect display name occurs only when Person field is populated programmatically? Or do you also see the incorrect name when entering the name manually?

After saving the form what is the value of the personUserManager field? Is it correct?

HI @mnikitina

Manually selected user works fine.

The issue appears when Person field is populated programmatically (like in your documentation). It doesn't matter if I use login name or email address.
Saved field has wrong data.
In my opinion it works this way:
code sets a login/email (fd.field('personUserManager').value = props[i].Value;) and form searches for display name. While searching display name (in code only login or email is provided') it looks for all site users who starts with or contain this login name. Result is an array and it takes last received Display Name. This all before save - we have good field value but wrong Display Name.
When form is being saved it takes Display Name (which is incorrect) and searches for site users and fills all other properties from wrong site user, even if login or email has already been provided for the field.

Regards
Marcin

@Marcin,

I couldn't reproduce the issue on my form.

Please try setting the Person or Group field value by user's key property using the code without pnp request:

fd.field('personUserManager').value = 'i:0#.w|dev\\m.nikitina'

image

To get user's key property, define fd globally by adding the below code to the first line in JS editor:

window.fd= fd;

Then, choose the user manually in Person or group field and get the value of the field using the code in browser console:

fd.field('FieldName').value

Hi @mnikitina !

Of course I had tried few attempts before I asked for help :slight_smile:

I got the same effect.

Regards
Marcin

@Marcin,

Since we can't reproduce the issue on our side, we need more information.

Developers are asking to do the following and share the screenshot of the result:

  1. Define fd globally. Add the below code to the first line in JS editor:

    window.fd= fd;
    
  2. Execute the following code in the browser console (replace User with the internal name of the field):

    fd.field('User').$on('change', v => console.log(v));
    
  3. Then select each user manually, expand the output in the console and make screenshots. You should see something like this:
    image
    Clik on three dots to show the property value.

  4. Then assign users by email/key (each user) with code:

    fd.field('User').value = 'some@email.com';
    

    And again, make a screenshot of the console output.