pre populating fields

Discussions about Forms Designer for SharePoint 2013 / 2016 and Office 365.
Locked
zwanetp3
Posts: 2
Joined: Mon Mar 20, 2017

21 Apr 2017

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

User avatar
Dmitry Kozlov
Site Admin
Posts: 1524
Joined: Thu Jun 07, 2012

21 Apr 2017

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 2522 times
Please, open the browser console (F12) and check if you have JS-errors or notifications there.

Locked
  • Information
  • Who is online

    Users browsing this forum: No registered users and 4 guests