This topic is locked
[SOLVED]

 Execute a Button event while checking other table record value

5/1/2018 6:20:58 AM
PHPRunner General questions
U
ustunsoz author

Hi Dears,
I am trying to execute an update event on selected records on list page with a button. However, before executing event I want to check a related record condition is met! I have tried to build following code as server event on this purpose.


// Put your code here.

global $dal;

while ( $data = $button->getNextSelectedRecord() )

{
//check support is done

$tblSupport = $dal->Table("mu_task_support");

$rs = $tblSupport->Query("IssueID=".$data["ID"]);

$data = db_fetch_array($rs);

if($data["Done"]=0)

System.out.println("There is unfinished job");

$result["txt"] = "Records not updated!";

$result["txt"] = $params["txt"]." NOT TERMINATED!";

break;
//end check
// set Closing Date today
$sql = "Update mu_task_tasks set Closing_Date=Now(), Active=0, Status=100, Percent_Complete=100 where ID=".$data["ID"];
CustomQuery($sql);
}
$result["txt"] = "Records were updated.";
$result["txt"] = $params["txt"]." Terminated!";


I have not succeeded to stop "while loop" if the related record condition returns false.

Can you help me to build a correct code

U
ustunsoz author 5/14/2018

I have solved based on post: http://asprunner.com/forums/topic/23140-how-to-update-status-of-record-in-on-click-on-the-list-page/
The only thing I should change was; the option related to other field.



//Set 'View as' type of 'status' field to 'Custom' and use the following code there

if ($data["Done"]!=1 AND $data["Job_Done"]==1)

$value="<a href=# onclick='$.post( \"save-click-support.php\", { ID: ".$data["ID"]." } );$(this).children(\"#image\").attr(\"src\",\"images/green.png\");

$(this).closest(\"td\").prev(\"td\").css(\"background\",\"#CFFFCF\");'>

<img src=images/red.png id='image'></a>";

elseif ($data["Done"]==1 AND $data["Job_Done"]==1)

$value="<img src=images/green.png id='image'>";

elseif ($data["Done"]!=1 AND $data["Job_Done"]!=1)

$value="<img src=images/red.png id='image'>";

elseif ($data["Done"]==1 AND $data["Job_Done"]!=1)

$value="<img src=images/red.png id='image'>";