Populate People Picker and Date fields with button click using JQuery

I have been trying to write some JS/JQuery code based on other examples I've seen for similar requirements, but I'm getting nowhere. I am not a developer and only know enough JS to be dangerous.


I need a button click to submit the answer to a question and populate a people picker field with the current user and a date field with the current date. Below is the code I have written in the form's custom Javascript field:

function SetAnswerInfo() {
   NWF$ ("#" + varAnswerBy).val(Current User);
   NWF$ ("#" + varAnswerDate).val(Current Date);

And in the button's client click field:


The fields to populate are on the form, but hidden behind the header since marking them not visible causes the form not to load. Both fields have been assigned the JS variables shown in the code above.


I am also using the button's "Connected to" feature to set the submission's status to "Answered".

The status is set as expected, but the code is not populating the Answered by and Date Answered fields.


Any ideas what I'm doing wrong?



0 Kudos
1 Reply

Re: Populate People Picker and Date fields with button click using JQuery

@cjones69 ....Instead of using JQuery, People/Group control and Date control, why don't you use calculated control?


In each calculated control, just use Current User and Currend Date from Common tab. You can even user UserProfileLookup function to manipulate Current User's information and Format Date run time function to manipulate Current Date & Time. If you need these information at the time of item creation only then don't re-calculate in view and edit mode. You can then connect this to people group column and date column or you can just simply use single line text column.

0 Kudos