This topic is locked
[SOLVED]

Custom Edit Button

9/12/2021 5:45:39 AM
Calendar Template general questions
D
drk2009 author

Hi,

I have added a table to the calendar template and I am trying to make it into an attendance tracking app.

img alt

I have added a custom button into the advance list view with the following code, to update the EndTime using an if statement, but it keeps updating even when the field "Edited" is not null.

Server Tab

function OnServer($params, $result)
{
$record = $button->getNextSelectedRecord();
If ($params["Edited"]="")
{
$result["txt"] = "Punch already updated.";}
else{
$Time = now();
$sql = "update Attendance set Edited='1', EndTime='$Time' where ID=".$record["ID"];
DB::Exec($sql);
}

Any assistance will be appreciated, I keep going around in circles.

D
drk2009 author 9/13/2021

I workit out - for anyone interested
Button Properties
Server Tab

$record = $button->getCurrentRecord();
//If the button is inserted in the grid on the List or Edit/View page,
//it returns an associative array (field name => value)
//Otherwise it returns false.
if ($record["Edited"])
{

}
else {
// get current time
$Time = now();
//Update SQL query - Update field Edited = 1 and EndTime field with Now()
$sql = "update Attendance set Edited='1', EndTime='$Time' where ID=".$record["ID"];
DB::Exec($sql);
}
$result["txt"] = "Punch was updated"

Client after

location.reload();