Fleshzombie Posted October 9, 2019 Report Share Posted October 9, 2019 I am trying to get a timestamp into a field "Cancel_Notification_Date" when the dropdown for field "Auction_Status" is set to "Cancelled" when the changes are made on a details page for a report, the script is currently in the footer. I have modified a script I found to what is shown below but it is not seeming to submit the data to the table when the form is submitted. The field type for Notification_Date is Text and it is in the details page as a text box currently during building of the page, eventually to become hidden when I get it to work. Anyone know the reason it is not pushing the timestamp into the table? <script type= "text/javascript"> function getT() { if(document.getElementById("EditRecordAuction_Status").value == 'Cancelled') { document.getElementById("EditRecordCancel_Notification_Date").value = '[@cbTimestamp~]'; } } document.getElementById("caspioform").onsubmit = getT; </script> Thank you for the help. Quote Link to comment Share on other sites More sharing options...
kpcollier Posted October 9, 2019 Report Share Posted October 9, 2019 @Fleshzombie, I think this would be easier with Triggered Actions. I have this setup for a lot of my apps using timestamps. You'll want to set this on an Update trigger. You'll want to set the block to UPDATE #inserted to make sure it is only going to set a timestamp for the record that was updated. You'll use the CASE block from Logic. In the WHEN section, use a AND block. Inside the AND block, you'll use 'Auction_Status equal Cancelled', as well as 'Timestamp is Blank' (more on this in a moment*). For the THEN part on the WHEN section, use the Account Timestamp field from the Date on the side toolbar. This is where it will stamp the current time. *In the ELSE section of the CASE block, set it to your timestamp field. The reason for this, along with the 'Timestamp is Blank' part, is to prevent users from corrupting this data. Without this, the Timestamp would be reset every time the Status was set to Cancelled. So, if someone wanted to fake the time is was actually cancelled, they could quickly just update the record's status to cancelled again to change the time. Setting ELSE to the timestamp field itself will prevent this. Picture below to show the setup. Quote Link to comment Share on other sites More sharing options...
Fleshzombie Posted October 9, 2019 Author Report Share Posted October 9, 2019 Thank you for the reply, Unfortunately our account does not have access to triggered Actions but that does look like it would be the easiest method to set this up. Also seeing your logic above I probably have to add another condition to the IF statement that keeps it from updating if there is already a value in the Cancel_Notification_Date field like you did. I have been looking into it a bit more and it seems that it may have to do with an update to the javascript/caspio bridge and ajax loading being the reason the code above doesnt work. Do I have to change document.getElementById("caspioform").onsubmit to something including document.addEventListener('DataPageReady', function (event) Quote Link to comment Share on other sites More sharing options...
Vitalikssssss Posted October 10, 2019 Report Share Posted October 10, 2019 Hi @Fleshzombie, You should use Caspio built-in event BeforeFormSubmit as an equivalent for JS onsubmit event if your Datapage has AJAX enabled. <script type="text/javascript"> document.addEventListener('BeforeFormSubmit', function (event) { // do something }); </script> Here is the reference from HowTo: 13-0-impacted-areas Regards, vitalikssssss Quote Link to comment Share on other sites More sharing options...
Fleshzombie Posted October 11, 2019 Author Report Share Posted October 11, 2019 @Vitalikssssss Thank you, I was able to figure it out and get it working. Quote Link to comment Share on other sites More sharing options...
carlJS Posted October 26, 2019 Report Share Posted October 26, 2019 Hello, You may also want to use Calculated Values for this. Below is the syntax I used in one of my workflows. CASE WHEN DATALENGTH('[@field:Cancel_Notification_Date]') > 0 AND [@field:Auction_Status] = 'Cancelled' THEN '[@field:Cancel_Notification_Date]' ELSE CAST( '[@cbTimestamp~]' as DATETIME ) END I hope this helps [src="carl.js"] 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.