Jump to content
  • 0

How to timestamp a field based on conditions in other fields


NikkiC

Question

Hi there,

I would like to timestamp a field (Test_Completed), but only if it hasn't already been timestamped and only if a different field (Actual_result) has content.

I found a forum answer about timestamping a field, and have tried to modify it to include my conditions, but I am not too good with JavaScript!  This is what I've done, can anyone help??

<SCRIPT LANGUAGE="JavaScript">
 /* Declaration and initialization */
 Stamp = new Date();
 var v_TimeStamp;
 Hours = Stamp.getHours()
 Mins = Stamp.getMinutes();
  
   /* Construct the value of the v_TimeStamp variable in the format m/d/yyyy hh:mm */
 v_TimeStamp=('' + (Stamp.getMonth() + 1) +"/"+Stamp.getDate()+ "/"+Stamp.getFullYear() + ' ' + Hours + ":" + Mins);

 if ('[@field:Actual_result]' === 'input.length >1' && '[@field:Test_Completed]' === "") {
 document.getElementById("EditRecordTest_Completed").value=v_TimeStamp;
 }
</SCRIPT>

Many thanks

Nikki

Link to comment
Share on other sites

4 answers to this question

Recommended Posts

  • 0
1 hour ago, NikkiC said:

Hi there,

I would like to timestamp a field (Test_Completed), but only if it hasn't already been timestamped and only if a different field (Actual_result) has content.

I found a forum answer about timestamping a field, and have tried to modify it to include my conditions, but I am not too good with JavaScript!  This is what I've done, can anyone help??


<SCRIPT LANGUAGE="JavaScript">
 /* Declaration and initialization */
 Stamp = new Date();
 var v_TimeStamp;
 Hours = Stamp.getHours()
 Mins = Stamp.getMinutes();
  
   /* Construct the value of the v_TimeStamp variable in the format m/d/yyyy hh:mm */
 v_TimeStamp=('' + (Stamp.getMonth() + 1) +"/"+Stamp.getDate()+ "/"+Stamp.getFullYear() + ' ' + Hours + ":" + Mins);

 if ('[@field:Actual_result]' === 'input.length >1' && '[@field:Test_Completed]' === "") {
 document.getElementById("EditRecordTest_Completed").value=v_TimeStamp;
 }
</SCRIPT>

Many thanks

Nikki

Hi Nikki,

I edited your script a little bit, try inserting script in the footer:

<SCRIPT LANGUAGE="JavaScript">
window.onload=function myfunc(){
 Stamp = new Date();
 var v_TimeStamp;
 Hours = Stamp.getHours()
 Mins = Stamp.getMinutes();
  
   /* Construct the value of the v_TimeStamp variable in the format m/d/yyyy hh:mm */
  v_TimeStamp=('' + (Stamp.getMonth() + 1) +"/"+Stamp.getDate()+ "/"+Stamp.getFullYear() + ' ' + Hours + ":" + Mins);

 if ('[@field:Actual_result]'.length>1 && '[@field:Test_Completed]' === "") {
 document.getElementById("EditRecordTest_Completed").value=v_TimeStamp;
 }
}
</SCRIPT>

Both fields should be editable text fields on a datapage, if you need to hide a field, you may use display:none attribute, like explained here

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
Answer this question...

×   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...