Jump to content

Timestamp When "y" Clicked


Recommended Posts

Hello,

 

In a table, there is a field (field 1) for selecting "Y" or "N", and default is set to N. However, I'd like another field (field 2) for a timestamp when it is updated to "Y". So, somehow field 2 should be connected to field 1, and I've written the following function so far for field 2 through a Data Page:

 

CASE
   WHEN [@field:NEF_Plan_of_Execution_Material_Support_Required] = 'Y' THEN GetUTCDate()
END
 
But it's not getting the timestamp for the exact time when field 1 was clicked "Y"; it's just getting the current server time.
 
Also, when creating a field in a table and assigning a DataType to it, there's an option for "Timestamp" and at the bottom some additional options for "Stamp on Insert" and "Stamp on Update", but there isn't a way to make it tie to another field. 
 
How should I go about completing this task of making field 2 a timestamp for when field 1 is updated to Y?
 
Thank you so much
Link to comment
Share on other sites

You can use this javascript to call a function to assign date when a checkbox is checked. Make sure to replace the IDs with corresponding IDs.

<script>
document.getElementById('ID OF CHECKBOX').onchange = function () {
if (document.getElementById('ID OF CHECKBOX').checked){
var currentdate = new Date();
var datetime =  currentdate.getDate() + "/"
                + (currentdate.getMonth()+1)  + "/"
                + currentdate.getFullYear() + " "  
                + currentdate.getHours() + ":"  
                + currentdate.getMinutes() + ":"
                + currentdate.getSeconds();
document.getElementById('ID OF DATE FIELD').value = datetime;
}
}
</script>
Link to comment
Share on other sites

Thanks for the reply.

 

I added this to the "Footer" section of details page on DataPage:

<script>
document.getElementById('SupportReady').onchange = function() {
if (document.getElementById('SupportReady').checked){
var currentdate = new Date();
var datetime =  currentdate.getDate() + "/"
                + (currentdate.getMonth()+1)  + "/"
                + currentdate.getFullYear() + " "  
                + currentdate.getHours() + ":"  
                + currentdate.getMinutes() + ":"
                + currentdate.getSeconds();
document.getElementById('Timestamp').value = datetime;
}
}
</script>

It doesn't seem to be working.

One concern I have is the part where it says "checked" - I'm wondering if it knows what it is checked to. How about if I do something like value=="Y"?

This is the code I have so far based off of info I got from caspio forums but it also isn't working:

<script>
 
function myFunction()
{
var v = document.getElementById("SupportReady").value;
if (v=='Y'){
  document.getElementById("Timestamp").value = "[@cbTimestamp]"; 
}
 
document.getElementById("caspioform").onsubmit=myFunction;

</script>

This is a Report DataPage. When clicking on details, "SupportReady" has radio buttons with 2 options Display:YES, Value:Y, and Display:NO, Value:N. 

Default value is N, and when it's updated to Y I want the field "Timestamp" to have a timestamp.

 

In Tables, SupportReady has DataType of "Text(255)".

Link to comment
Share on other sites

Now that you have radio buttons if the yes option is the first option try this code in an HTML Block at the end of element list:

<script>
document.getElementById('EditRecordSupportReady0').onclick= function () {
if (document.getElementById('EditRecordSupportReady0').value == 'Y'){
var currentdate = new Date();
var datetime = currentdate.getDate() + "/"
                + (currentdate.getMonth()+1)  + "/"
                + currentdate.getFullYear() + " "  
                + currentdate.getHours() + ":"  
                + currentdate.getMinutes() + ":"
                + currentdate.getSeconds();
document.getElementById('Timestamp').value = datetime;
}
}
</script>

This should work. If not working for you provide me the link of the page

Link to comment
Share on other sites

On the Results Page, the column "Timestamp" is the field for timestamp. There is no field for "Timestamp" in the details page, although there could be if necessary. I'm wondering how the code could specify what's shown on Details Page and what's shown on Results Page.

 

In the Tables, I changed the datatype for the "Timestamp" field to Date/Time when it used to be Text(255), but it doesn't seem to be working. 

 

Is the code saying that the field "Timestamp" will be changed as soon as "Y" is clicked? How about doing the function when the update button is clicked, or something like 

document.getElementById("caspioform").onsubmit=myFunction;

?

Link to comment
Share on other sites

I tried this:

<script>
function myFunction() {
if (document.getElementById('EditRecordSupportReady0').value == 'Y'){
var currentdate = new Date();
var datetime = "Last Sync: " + currentdate.getDate() + "/"
                + (currentdate.getMonth()+1)  + "/"
                + currentdate.getFullYear() + " "  
                + currentdate.getHours() + ":"  
                + currentdate.getMinutes() + ":"
                + currentdate.getSeconds();
document.getElementById('Timestamp').value = datetime;
}
}

document.getElementById("caspioform").onsubmit=myFunction();
</script>

But it's also not doing it..

 

I've tried adding it in Footer section, I've tweaked with changing it to ('EditRecordSupportReady')[0], etc. but it doesn't seem to be working...

 

Here are some extra info just in case:

 

Tables

SupportReady = Text(255)

Timestamp = Date/Time

 

DataPage - Report

Results Page

SupportReady = Render value as: Text, Formatting: None

Timestamp = Formatting: None

 

Details Page

SupportReady = Radio buttons

HTML Block = where code inputted

 

 

 

 

Anyone have any ideas?

Link to comment
Share on other sites

You do not need to change the format since I had it work in my account. Make sure Timestamp filed is included in the details page as well. I am still not seeing this field.

 

The issue should be this line:

 

document.getElementById('Timestamp').value = datetime;

 

The Timestamp need to be replaced with the correct ID. Is the field name is Timestamp in the table it needs to be included in the details page and the ID would be EditRecordTimestamp

 

You can call the function onsubmit as well.

Link to comment
Share on other sites

I changed the line to 

 

document.getElementById('EditRecordTimestamp').value=datetime;

 

and the Timestamp field is included in the Details Page.

 

But it's not working...

 

 

Thanks so much for your help so far by the way - I can't thank you enough.

Link to comment
Share on other sites

I would really appreciate any feedback on this - 

 

Here are some other forum threads very similar to this.

 

http://forums.caspio.com/index.php/topic/3488-time-stamp-field-based-on-selection-in-drop-down/

http://forums.caspio.com/index.php/topic/3547-if-then-and-else-for-timestamp/

http://forums.caspio.com/index.php/topic/3567-how-do-you-timestamp-when-the-checkbox-is-checked/

 

I've tried their code as well, and changing my SupportReady to checkbox, dropdown, etc. and changing the DataType around, but it doesn't seem to be working. Thoughts? This should be relatively simple.

 

Thanks so much

Link to comment
Share on other sites

MayMusic - Thanks so much, it is working now.

 

For those interested in the solution, 

The additional problem was that Timestamp field in the Table had to have a datatype of Text(255).

In the Details Page, Timestamp was changed to a Text Field. Once Yes was clicked, the textfield was filled with a timestamp, and then when Update was clicked, the field in the Results Page was filled with the timestamp.

 

Thanks again.

Link to comment
Share on other sites

<script>
var currentdate = new Date();
var datetime = currentdate.getDate() + "/"
                + (currentdate.getMonth()+1)  + "/"
                + currentdate.getFullYear() + " "  
                + currentdate.getHours() + ":"  
                + currentdate.getMinutes() + ":"
                + currentdate.getSeconds();

document.getElementById('EditRecordSupportReady0').onclick= function () {
if (document.getElementById('EditRecordSupportReady0').value == 'Y'){

document.getElementById('EditRecordSupportRequiredYes').value = datetime;
document.getElementById('EditRecordSupportRequiredYes').disabled= true;
}
else if (document.getElementById('EditRecordSupportReady1').value == 'Y') {
document.getElementById('EditRecordSupportRequiredYes').value = "" ; 

}
}


document.getElementById('EditRecordSupportReady0').onclick= function () {
if (document.getElementById('EditRecordSupportReady0').value == 'Y'){

document.getElementById('EditRecordSupportReadyYes').value = datetime;
document.getElementById('EditRecordSupportReadyYes').disabled= true;
}
else if (document.getElementById('EditRecordSupportReady1').value == 'Y') {
document.getElementById('EditRecordSupportReadyYes').value = "" ; 

}
}

</script>

This code should make the visible text field disabled so user cannot change and also to remove the value from hidden text field since if user selects Yes first the date will appear on text field and now if checks no the field is hidden but the value is there so we need to remove the value now 

 

I have  not tested the code but it should work

Link to comment
Share on other sites

Thank you so much, the fields are non-editable and everything is working now. 

 

Here is my code:

 
<script>

document.getElementById('EditRecordSupportReadyYes').disabled= true;
document.getElementById('EditRecordSupportRequiredYes').disabled= true;

document.getElementById('EditRecordSupportRequired0').onclick= function () {
if (document.getElementById('EditRecordSupportRequired0').value == 'Y'){
var currentdate = new Date();
var datetime = (currentdate.getMonth()+1)  + "/"
                + currentdate.getDate() + "/"
                + currentdate.getFullYear() + " "  
                + currentdate.getHours() + ":"  
                + currentdate.getMinutes();
document.getElementById('EditRecordSupportRequiredYes').disabled= false;
document.getElementById('EditRecordSupportRequiredYes').value = datetime;
document.getElementById('EditRecordSupportRequiredYes').disabled= true;
}
}
document.getElementById('EditRecordSupportRequired1').onclick= function () {
if (document.getElementById('EditRecordSupportRequired1').value == 'N'){
document.getElementById('EditRecordSupportRequiredYes').disabled= false;
document.getElementById('EditRecordSupportRequiredYes').value = "";
document.getElementById('EditRecordSupportRequiredYes').disabled= true;
}
}

document.getElementById('EditRecordSupportReady0').onclick= function () {
if (document.getElementById('EditRecordSupportReady0').value == 'Y'){
var currentdate = new Date();
var datetime = (currentdate.getMonth()+1)  + "/"
                + currentdate.getDate() + "/"
                + currentdate.getFullYear() + " "  
                + currentdate.getHours() + ":"  
                + currentdate.getMinutes();
document.getElementById('EditRecordSupportRequiredYes').disabled= false;
document.getElementById('EditRecordSupportReadyYes').value = datetime;
document.getElementById('EditRecordSupportReadyYes').disabled= true;
}
}
document.getElementById('EditRecordSupportReady1').onclick= function () {
if (document.getElementById('EditRecordSupportReady1').value == 'N'){
document.getElementById('EditRecordSupportRequiredYes').disabled= false;
document.getElementById('EditRecordSupportReadyYes').value = "";
document.getElementById('EditRecordSupportReadyYes').disabled= true;
}
}

function enableElements(){
document.getElementById('EditRecordSupportRequiredYes').disabled= false;
document.getElementById('EditRecordSupportReadyYes').disabled= false;
}

document.getElementById("caspioform").onsubmit=enableElements;

</script>

I had to add the function at the end and extra .disabled lines everywhere because initially the .disabled made it so that when I clicked Update, the timestamps wouldn't show. 

 

 

=) Thanks again.

Link to comment
Share on other sites

  • 8 years later...

Tried MayMusic's script it works good, but im trying to do multiple radio buttons to enter timestamp into another date feild example start monitoring, contacted local attendant, attendant responded and end monitoring. Each to have its radio button to stamp the time. I revised the code to respond accordingly but each radio button updates the time stamp on all date/time fields. I hope Caspio can do what we are hoping for. Thanks.

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