Page 1 of 1

pre populating fields

Posted: 21 Apr 2017
by zwanetp3
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");

Re: pre populating fields

Posted: 21 Apr 2017
by Dmitry Kozlov
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:
UserFieldPrepopulation.png
UserFieldPrepopulation.png (1.32 KiB) Viewed 2528 times
Please, open the browser console (F12) and check if you have JS-errors or notifications there.