Dears,
i need to get the currently logged in user name and manager and assign them to person fields in my sharepoint online list.
i have tried the following expression :
fd.field('EMP').value = _spPageContextInfo.userLoginName;
EMP is a person field addede to the new form.
but it is giving me the name of another user not the logged in one.
is there any suggestion from anybody.
@Nikita_Kurguzov
Good day! in sharepoint 2019, i have the same problem...
for example there are 2 users with some identic account.
when i use _spPageContextInfo.userDisplayName and enter the second user - olesea.luchian it returns the first user and populate department ,email, etc of first user..
i tried userEmail the same.
userId... - can't use it , because there some internal office Code. which for example if it return 58, it can be another person too...
how can obtain unique current user ?
Dear @ixxxl,
Using email address should select the correct user. Are you sure that everything is setup correctly in user profiles? Can you check the emails of the users?
Also, check the value when you select it manually:
@Nikita_Kurguzov
it is ok with user email in console , the are different.
the problem is only with populating Person field with current user, and then getting userInfo from this people picker.
instead i think i need to use as you say previously -
and then populate a text field with current user Display Name, and not Person field. because with person the same trouble, it selects the first one user of two similar names.
@Nikita_Kurguzov
good day..
my problem is continued.
when i try to populate person field with _spPageContextInfo.userLoginName or _spPageContextInfo,.userEmail. it returns first user in search of person field and not the correct user.
in screen is example of manual selecting user.
at populating is the same. when Diana V.Botanri created item in person field is returned Diana Botnariuc the first one. in list Created by is corect person - Diana V.Botnari. and workflow works fine. Problem only with populating person field.
Dear @ixxxl,
If you enter the email manually, is there the same issue? If it's a default SharePoint form not customized with Plumsail Forms, does it work any different?
@Nikita_Kurguzov
i create a new list,without plumsail form, added a person field(single) - put email and it show 2 variants of users. the same issue, only that it sorts another way, it seems from the end to begin
Dear @ixxxl,
In this case, the issue is not with forms, we use the same end points that regular SharePoint forms use. You might need to adjust user data in Azure AD.
@Nikita_Kurguzov
this one , works good for me. but it is in button, and update works only for existing item.
how can i use it for new item form? is it a way to get sharepoint user id ?
Dear @ixxxl,
Unfortunately, the field on the form can only be populated with email. User ID might work for populating field, that's not on the form, applying changes directly to the item itself with pnpjs.