Make field go blank after Save As Copy

Discussions related to customizing hooks. Hooks are documented at http://bigprof.com/appgini/help/advanced-topics/hooks/
Post Reply
rpierce
Veteran Member
Posts: 255
Joined: 2018-11-26 13:55
Location: Washington State

Make field go blank after Save As Copy

Post by rpierce » 2022-06-07 22:13

Is there a way you could cause a date field to be blank immediately after the Save as Copy function is used?

I have a table with several children tables. Project managers enter information for a daily report. Often much of the information is the same from day to day so we use the Save as Copy function.

The problem I would like to resolve is the creation of records with incorrect dates. Sometimes when a person does a Save as Copy, they jump right in to editing what they need to change and then save the record without remembering to change the date. The date field is required so if they tried to save the record with a blank date the system would yell at them.

Any cool code to make this happen??

Ray

Alisson
Veteran Member
Posts: 81
Joined: 2017-02-25 20:32

Re: Make field go blank after Save As Copy

Post by Alisson » 2022-06-09 22:09

Try this in your tablename.php in hooks folder, insert this code inside the function "tablename_after_insert":

Code: Select all

    $source_id = makeSafe($_REQUEST['SelectedID']);
    if($source_id) { 
	$date = sqlValue("SELECT `date` FROM `tableNameHere` WHERE `id`='{$source_id}'");
	update('tableNameHere', ['date' => null], ['id' => $data['selectedID']]);
    }
After Save as Copy is clicked the new

rpierce
Veteran Member
Posts: 255
Joined: 2018-11-26 13:55
Location: Washington State

Re: Make field go blank after Save As Copy

Post by rpierce » 2022-07-22 17:46

Hi Alisson,

I tried your suggestion with no luck. The new record continues to have the same date as to copied record.

Post Reply