User name when completing New Form
Posted: 25 Jun 2019
Hi
I'm trying to get the user's name autopopulated onto a New form when they are filling it in.
I've tried this, running when the form is opened:
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 () {
fd.field('Report_x0020_Document_x0020_Cont').control().value(value(user.get_loginName()));
fd.field('Report_x0020_Document_x0020_Cont').control()._el().find('a:eq(0)').click();
alert(value(user.get_loginName()));
});
}), "SP.js");
But it errors, saying that the field ('Report_x0020_Document_x0020_Cont') doesn't exist.
Can you let me know what's going wrong? Or let me know how else I can autopopulate the user name in a New form?
Thanks
I'm trying to get the user's name autopopulated onto a New form when they are filling it in.
I've tried this, running when the form is opened:
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 () {
fd.field('Report_x0020_Document_x0020_Cont').control().value(value(user.get_loginName()));
fd.field('Report_x0020_Document_x0020_Cont').control()._el().find('a:eq(0)').click();
alert(value(user.get_loginName()));
});
}), "SP.js");
But it errors, saying that the field ('Report_x0020_Document_x0020_Cont') doesn't exist.
Can you let me know what's going wrong? Or let me know how else I can autopopulate the user name in a New form?
Thanks