Page 1 of 1

New Form: When the people picker field is set to read only, the field is not displayed

Posted: 15 May 2020
by TWendt
Hello all,

i add a script to a people picker field, so that the logged in user is automatically entered. When i set the field to read only, it is not displayed. Can I use a script or what can I do?

Here is my script:
// Load current user login
SP.SOD.executeOrDelayUntilScriptLoaded((function () {
var ctx = new SP.ClientContext.get_current();
var web = ctx.get_web();
ctx.load(web);
var user = web.get_currentUser();
user.retrieve();
ctx.executeQueryAsync(
function () {
// Set user login
fd.field('User_x0020_name').control().value(user.get_title());
// Run validation by emulating validation image click
fd.field('User_x0020_name').control()._el().find('a:eq(0)').click();
});
}), "SP.js");

Best wishes and take care
Tom

Re: New Form: When the people picker field is set to read only, the field is not displayed

Posted: 15 May 2020
by mnikitina
Hello Tom,

What SharePoint version are you using? Online or On-Premises?

Please share the complete code that is related to User_x0020_name field and the screenshot of the form.

Thank you!

Re: New Form: When the people picker field is set to read only, the field is not displayed

Posted: 15 May 2020
by TWendt
Hello Mnikitina,

this is the complete script. I use SharePoint 2013 on premise.
New-Form-01.JPG
New-Form-01.JPG (40.57 KiB) Viewed 6516 times
New-Form.JPG
New-Form.JPG (80.33 KiB) Viewed 6516 times

Re: New Form: When the people picker field is set to read only, the field is not displayed

Posted: 18 May 2020
by mnikitina
Hello Tom,

It is not possible to set the people picker field value when the field is disabled. So you need to enable it first, populate with the user name and disable.

Code: Select all

//enable field
fd.field('User_x0020_name').readonly(false);
// Load current user login
SP.SOD.executeOrDelayUntilScriptLoaded((function () {
var ctx = new SP.ClientContext.get_current();
var web = ctx.get_web();
ctx.load(web);
var user = web.get_currentUser();
user.retrieve();
ctx.executeQueryAsync(
function () {
// Set user login
fd.field('User_x0020_name').control().value(user.get_title());
// Run validation by emulating validation image click
fd.field('User_x0020_name').control()._el().find('a:eq(0)').click();
});
}), "SP.js");
//disable field
fd.field('User_x0020_name').readonly(true);

Re: New Form: When the people picker field is set to read only, the field is not displayed

Posted: 19 May 2020
by TWendt
Hello Mnikitina,

many thanks for your support. It works.

Best wishes and take care.
Tom