You are viewing limited content. For full access, please sign in.

Question

Question

Inserting local machine Time into Form's Field?

asked on December 2, 2014 Show version history

Hello Everyone

 

I had this issue long time ago but I wasn't able to figure it out.    All I need is to get device's (tablet or PC) time  into Form's Field.   I used {/dataset/_initiated_time} as default value for the field but still does not show the time.  

 

I could appreciate some help

Thanks

 

0 0

Answer

SELECTED ANSWER
replied on December 3, 2014

If you use " {/dataset/_initiated_time}" on a form used in message start event, the value for the token will be blank when open the form for the process is not initiated until you submit the form. You can use similar JavaScript as following to get and set the current time:

$(document).ready(function(){
  
  function setcurrenttime (){
  var currentdate=new Date();
  var datetimenow=(currentdate.getMonth()+1)+ "/"+currentdate.getDate()
    + "/" + currentdate.getFullYear() + " " 
    + currentdate.getHours() + ":" 
    + currentdate.getMinutes() + ":" + currentdate.getSeconds();

  $('#Field15').val(datetimenow);
  }
  setcurrenttime();
})

 

0 0
replied on December 5, 2014 Show version history

Hello Xiuhong

 

With some modification I got your code working.     Now the time shows correctly on the form, thanks for that.

Now I realized that when I submit the form (which is saved to repository in PDF format) the time does not show on the PDF image of the submitted form.

 

I am suspecting when I submit it the time field is set to empty.   Any thoughts on that?

 

 

 

------- $(document).ready(function(){
   
  function setcurrenttime (){
      var currentdate=new Date();
      var datetimenow=(currentdate.getHours())+ ":"
        + currentdate.getMinutes();
    
      $('#Field280').val(datetimenow);
      }
      setcurrenttime();
    });-----

0 0

Replies

replied on December 3, 2014

Thank you Xiuhong it was right on, this was exactly what I was looking for.

0 0
replied on April 11, 2017

Thank you Xiuhong for your code- How do I modify it to add the leading or trailing 0's so the format is MM/dd/yyyy hh:mm:ss  - Right now the output is 4/11/2017 16:3:57

0 0
replied on April 14, 2017

You can just change it  the line for set value to following:

$('#Field15').val(moment(datetimenow).format("MM/DD/YYYY hh:mm:ss a"));

 

1 0
replied on April 14, 2017

Thank you Xiuhong!!

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.