Compare User ID to ID of People Picker field

Hello Everybody

I am currently trying to make a Form a little bit dynamic in term of disabling fields depending on which user is looking at them.

I have these two fields in a form in which the Field "CTO" is already filled out. So the "onChange" Function does not work for my example.

This is the JS-Code i use within the Form-Editor.

dont mind the ending as this is a cutted Image and the function closes correctly.

I think the code for getting the actual User ID is correct but what i'm confused about is how to get the ID of the already filled out People Picker Field.

Kind regards,
Dario

Hello @Dario_Chiga,

You can get the Id of the user selected in the Person or Group field using this code:

let web = new Web('RootSsiteUrl');
var userEmail = fd.field('FieldName').value.Description;
web.siteUsers.getByEmail(userEmail ).get().then(function(properties){
    alert(properties.Id)
});
1 Like

So now my code looks like this but it still doesnt work.

@Dario_Chiga,

You can get the current user ID using this code:

_spPageContextInfo.userId

And you need to use a tenant URL: https://qmedicsag.sharepoint.com

So the code is this:

let web = new Web('https://qmedicsag.sharepoint.com');
var userEmail = fd.field('FieldName').value.Description;
web.siteUsers.getByEmail(userEmail).get().then(function(properties){
    alert(properties.Id)
});

If you want to know the Id of the user who created the item, you can get it like this:

fd.field('Author').value.id

well that description was a lot more complicated then it should have been with the whole "new web" and such.
all i had to do to get both ID's is:

works like a charm.

2 Likes