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

Discussions about Forms Designer for SharePoint 2013 / 2016 and Office 365.
Locked
TWendt
Posts: 109
Joined: Mon Sep 08, 2014

15 May 2020

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

User avatar
mnikitina
Posts: 264
Joined: Wed Jun 05, 2019

15 May 2020

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!

TWendt
Posts: 109
Joined: Mon Sep 08, 2014

15 May 2020

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 6496 times
New-Form.JPG
New-Form.JPG (80.33 KiB) Viewed 6496 times

User avatar
mnikitina
Posts: 264
Joined: Wed Jun 05, 2019

18 May 2020

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);

TWendt
Posts: 109
Joined: Mon Sep 08, 2014

19 May 2020

Hello Mnikitina,

many thanks for your support. It works.

Best wishes and take care.
Tom

Locked
  • Information
  • Who is online

    Users browsing this forum: No registered users and 12 guests