Forum Discussion
CarlosCarlos
8 years agoQrew Assistant Captain
Is there a way to get the current date/time (on a button and then to a field) when the user hasn't refreshed the page in a couple of hours? (Attempting to track time dedicated to work, so they open a record when they start to work on a given task, but they consistently fail to refresh before closing it (using a button) so it stores the date/time of the last page refresh, instead of the current time.
- MichaelBarrow8 years agoQrew CadetYeah, very frustrating! I would love an answer to this, as it makes my time sheet app much more difficult to use for my end users. Is there some clever javascript that can be added to a button to overcome this?
- CarlosCarlos8 years agoQrew Assistant CaptainMichael, I think i just got it.! (there are references to someone else's code here... cannot remember who or where. If anyone feels they should be credited, please say so!)
Formula URL Button:"javascript:" &
"var QBU_key = '" & [Record ID#] & "';" &
"$.getScript(gReqAppDBID + '?a=dbpage&pagename=STOPACTIVITY.js');" &
"void(0);"
Then the JS File (STOPACTIVITY.js):var apptoken = "type_the_apptoken_here";
$.ajaxSetup({data: {apptoken: apptoken}});
//this one prompts the user for an input describing what he'd been doing...
var motive = prompt("In this activity I was doing: ");
//this is the basic setup for the date. TimeZone for US timeZones and format you may change es-CR to en-US and the timeZone to America/New_York, etc. hour12:true will display in 12 hour format. False will display as 24h.
var event = new Date(Date.now());
date = event.toLocaleString('es-CR', { timeZone: 'America/Costa_Rica', hour12:true} );
if(motive == null){
alert("No task description was input. No changes were performed.");
record
}else {
var promise = $.get(gReqDBID,{
act: "API_EditRecord",
rid: QBU_key,
_fid_12: motive,
_fid
_fid_57: date
});
alert("Activity Ended.");
location.reload();
} - MichaelBarrow8 years agoQrew CadetThank you! I will give this a try when I get back in the office._