GeorgeSmith Posted October 24, 2011 Report Share Posted October 24, 2011 Hi, I'm trying to time stamp a field based upon the selection that is done from a drop down menu. When the user does this they will be inside of a Details Page within a Report Form. When the user changes the "Status" field of their current task in the Details Page to "In-progress" I want a one-time time stamp of that event to be recorded in the field "StartTime". Here is the Java script I have written, and placed in the Footer of the Details Page but currently it's not working, function getT(){ if('[@field:Status]' == 'In-progress'){ document.getElementById("EditRecordStartTime").value = '[@cb:Timestamp]'; } } document.getElementById("caspioform").onsubmit = getT; I think this should be pretty straight forward, but I'm not sure why it's not working. Thanks for any help. Quote Link to comment Share on other sites More sharing options...
ShWolf Posted October 27, 2011 Report Share Posted October 27, 2011 Hi, Try this one: <script type= "text/javascript"> function getT() { if(document.getElementById("EditRecordStatus").value == 'In-progress') { document.getElementById("EditRecordStartTime").value = '[@cb:Timestamp]'; } } document.getElementById("caspioform").onsubmit = getT; </script>When you use the [@field:Status] placeholder, the value is inserted into it on page load. But you want to take current value of the field, e.g. if a user changed it. So you have to use document.getElementById("EditRecordStatus").value.Also, the StartTime field should be Hidden or Editable. If it's Display Only, no element with appropriate id is rendered to the page. I guess, that was the main reason of your script not working. Please also note that [@cb:Timestamp] gets the date and time on page load. It's fine if it suffices for you, otherwise you should take current date with javascript and format it according to your needs. Hope this helps. Quote Link to comment Share on other sites More sharing options...
GeorgeSmith Posted October 27, 2011 Author Report Share Posted October 27, 2011 OMG thank you so much, it worked! Quote Link to comment Share on other sites More sharing options...
iren Posted January 21, 2015 Report Share Posted January 21, 2015 Hi. Is there any way to record a timestamp when a specific field is updated? Quote Link to comment Share on other sites More sharing options...
Jan Posted January 21, 2015 Report Share Posted January 21, 2015 Hi iren, You can create a Virtual field and select Hidden Form element. In Field Options of the Virtual field, select Data Source Fields and your field (for example, Status). This Virtual field will "remember" the initial value of the field. Then add a Header&Footer element, select Footer, click Source and enter the following code: <script type= "text/javascript"> function getT() { if(document.getElementById("EditRecordStatus").value != document.getElementById("cbParamVirtual1").value) { document.getElementById("EditRecordTime_edited").value = '[@cb:Timestamp]'; } } document.getElementById("caspioform").onsubmit = getT; </script> Enter names of your fields instead of Status and Time_edited and change the number of the Virtual field in cbParamVirtual1, if the added Virtual field is not the first. Also make the Time_edited field hidden in the details/update form because you don't want user to be able to update it. I hope, it helps. MAmbrose 1 Quote Link to comment Share on other sites More sharing options...
iren Posted January 21, 2015 Report Share Posted January 21, 2015 Hi Jan. Thank you, it works! Quote Link to comment Share on other sites More sharing options...
bahar_vm Posted January 21, 2015 Report Share Posted January 21, 2015 The script below records date/time (timestamps) when a specific field (in my case Status field) is updated. You don't need any virtual field. Place the script in the Footer of your details/update page. Status is my dropdown field (it could be a text field as well). Time_status_edited is a hidden field to store the timestamp upon updating the Status field. <script type= "text/javascript"> function getT() { var prevValue='[@field:Status]'; if(document.getElementById("EditRecordStatus").value != prevValue) { document.getElementById("EditRecordTime_status_edited").value = '[@cb:Timestamp]'; } } document.getElementById("caspioform").onsubmit = getT; </script> MAmbrose 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.