I am trying to find solution for counting time of survey completion? Is it even possible without visual studio development? - I need to know when user starts and complete survey.

SPServices? jQuery? any examples or tutorials?

2 Answers 2


If I assume that your scenario is as following: - User Clicks on the survey link - Survey form Opens - Counter is displayed to tell the user you have for example 30mn to complete the survey.

My solution will be: - A Javascript solution is possible via setInterval function like this:

var start = new Date;
var elapsedTime = 0; // in seconds

setInterval(function() {
   elapsed = (new Date - start)/1000;              
}, 1000);

// assume that this function is called when the users save the survey
// Perhaps perhaps an event on the Save Button or the default presave
// function of SP forms. It depends on your implemtation
function onSaveButtonFired(){
    // Take the elapsed time and save it wherever you want :)
  • Now, how to integrate this code? : 1- Integrate the JS code directly to the form page (via SP Designer or Other code editor) (No VS) 2- Implement JSLink attached to the form (NO need to VS either)

Of course when I say no need for VS I mean no need for a SharePoint App solution :) Tell me if this scénario fits yours

  • We are almost there :) - User clicks on the survey link -> timer starts from 0:00 -> User save survey -> timer stops and I have his time on hidden column, jquery variable or whatever is possible. I need this time in report later on so it need to be saved somewhere. Jan 5, 2016 at 14:01
  • Solution updated.
    – must19
    Jan 5, 2016 at 14:11
  • var start = new Date; var elapsedTime = 0; // in seconds setInterval(function() { elapsed = (new Date - start)/1000; console.log(elapsed); }, 10); function PreSaveAction() { alert(elapsed); return true; } It is exactly what i wanted but know I need help with saving this data. Is it possible to add elapsed time to current user survey answer as additional column? Jan 5, 2016 at 14:50
  • You need at least 2 lists : 1- Survey List to hold the survey Description; 2- Survey Results to save and track the users answers. The elapsedTime must be saved for each user and survey in the Result list. So yes if you are working with this configuration you can add the column to List.
    – must19
    Jan 5, 2016 at 14:57
  • One more question. When I dont check all anwers in survey page is refreshed and counter starts again from 0. Do you know any solution to prevent that? Jan 5, 2016 at 15:03

I just mixed up some code which takes current user, elapsed time and create new item on new list called in this case "Wyniki" and now I have time and current username as I wanted but... There is a small problem. When two users end survey at exact same time lets say 12:32:33 I get only one completion time. Is there a way to prevent that? Is it possible to save two, three, ten elements on list at exact same time using $.ajax?

var start = new Date;
var elapsedTime = 0; // in seconds
var userid = _spPageContextInfo.userId;
var loginName;

setInterval(function() {
    elapsed = (new Date - start)/1000;
}, 10);

function GetCurrentUser() {
    var requestUri = _spPageContextInfo.webAbsoluteUrl + "/_api/web/getuserbyid(" + userid + ")";

    var requestHeaders = { "accept" : "application/json;odata=verbose" };

        url : requestUri,
        contentType : "application/json;odata=verbose",
        headers : requestHeaders,
        success : onSuccess,
        error : onError

function onSuccess(data, request){
    loginName = data.d.Title;

function onError(error) {

function PreSaveAction() {
    var listName = "Wyniki";
    var imieNazwisko = loginName;
    var czas = elapsed;
    CreateListItemWithDetails(listName, _spPageContextInfo.webAbsoluteUrl, imieNazwisko, czas, function () {

    }, function () {
        //alert("Niestety wystąpił błąd. Spróbuj ponownie.");
    return true;

// CREATE Operation
// listName: The name of the list you want to get items from
// weburl: The url of the web that the list is in.
// newItemTitle: New Item title.
// success: The function to execute if the call is sucesfull
// failure: The function to execute if the call fails
function CreateListItemWithDetails(listName, webUrl, imieNazwisko, czas, success, failure) {
    var itemType = GetItemTypeForListName(listName);
    var item = {
        "__metadata": { "type": itemType },
        "Title": imieNazwisko,
        "Czas": czas

        url: _spPageContextInfo.siteAbsoluteUrl + "/_api/web/lists/getbytitle('" + listName + "')/items",
        type: "POST",
        contentType: "application/json;odata=verbose",
        data: JSON.stringify(item),
        headers: {
            "Accept": "application/json;odata=verbose",
            "X-RequestDigest": $("#__REQUESTDIGEST").val()
        success: function (data) {
        error: function (data) {

// Get List Item Type metadata
function GetItemTypeForListName(name) {
    return "SP.Data." + name.charAt(0).toUpperCase() + name.split(" ").join("").slice(1) + "ListItem";

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.