pre populating fields
Hi
I am trying to pre populate information in a form based on the user that is currently logged in. I am using the below function by clicking JS on the form and changing the field name to my fields internal name but nothing happens, please assist
// 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('Customer').control().value(user.get_loginName());
// Run validation by emulating validation image click
fd.field('Customer').control()._el().find('a:eq(0)').click();
});
}), "SP.js");
I am trying to pre populate information in a form based on the user that is currently logged in. I am using the below function by clicking JS on the form and changing the field name to my fields internal name but nothing happens, please assist
// 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('Customer').control().value(user.get_loginName());
// Run validation by emulating validation image click
fd.field('Customer').control()._el().find('a:eq(0)').click();
});
}), "SP.js");
- Dmitry Kozlov
- Site Admin
- Posts: 1524
- Joined: Thu Jun 07, 2012
Hi,
I've just put the code into JS-editor, replaced Customer with User since its the internal name of my User and Group column. And it's populated with the current user on loading the form: Please, open the browser console (F12) and check if you have JS-errors or notifications there.
I've just put the code into JS-editor, replaced Customer with User since its the internal name of my User and Group column. And it's populated with the current user on loading the form: Please, open the browser console (F12) and check if you have JS-errors or notifications there.
-
- Information
-
Who is online
Users browsing this forum: No registered users and 3 guests