Jump to content

time stamp field based on selection in drop down?


Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • 3 years later...

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.

Link to comment
Share on other sites

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>
Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...