where is Save As Copy Function ??

Discussions related to customizing hooks. Hooks are documented at http://bigprof.com/appgini/help/advanced-topics/hooks/
xbox2007
Veteran Member
Posts: 129
Joined: 2016-12-16 16:49

where is Save As Copy Function ??

Post by xbox2007 » 2020-04-06 20:52

hello

already use tablename_after_update() to insert date to other tables

but i would like use Save As Copy Function to insert new record in table and also insert date to other tables

i dont know where i can find or create Save As Copy Function ??

thanks a lot

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1635
Joined: 2018-04-01 10:12

Re: where is Save As Copy Function ??

Post by pbottcher » 2020-04-06 21:01

Hi,
just use the tablename_after_insert function. You have all the data in the $data array to do what you need.
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

xbox2007
Veteran Member
Posts: 129
Joined: 2016-12-16 16:49

Re: where is Save As Copy Function ??

Post by xbox2007 » 2020-04-06 23:09

thanks for your replay ,
tablename_after_insert will insert data on other table once i press Save

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1635
Joined: 2018-04-01 10:12

Re: where is Save As Copy Function ??

Post by pbottcher » 2020-04-07 06:20

in tablename_after_insert you can use the data in the "data" array and e.g. call a sql statement to insert the data into another table. This will happen after you press the save button on your site.
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

xbox2007
Veteran Member
Posts: 129
Joined: 2016-12-16 16:49

Re: where is Save As Copy Function ??

Post by xbox2007 » 2020-04-07 08:35

thanks again

you are right
if i use tablename_after_insert ,,, if user add new row (( add new )) once he press Save .

Save As Copy ===> make copy off database row and add in same table with now ID ...

for Example
in my project ,
user make some change like Date and when press Save As Copy will have two row ,
one is old row and new one with new information .

extra I want run sql statement to insert the data into another table when press Save As Copy.

(( i already use run sql statement to insert the data into another table with tablename_after_Update) and its work fine

thanks a lot

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1635
Joined: 2018-04-01 10:12

Re: where is Save As Copy Function ??

Post by pbottcher » 2020-04-08 21:19

Hi,

maybe I still do not get what you want. If the users hits the safe as copy AppGini will treat this like if you would insert a new record.
So all the hooks before_insert and after_insert apply.

So if you want just to put the data into another table, but dont actually store that data in the same table, you can either use the before_insert hook, run your sqlstatement to insert the data into the other table and return false. If you return false, the record will not be entered into the actual table ( but you will get an alert).
Otherwise you can use the after_insert hook to run your sqlstatement and delete the actual record from your actual table. Like this you just increase your auto_increment.
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

User avatar
onoehring
AppGini Super Hero
AppGini Super Hero
Posts: 1156
Joined: 2019-05-21 22:42
Location: Germany
Contact:

Re: where is Save As Copy Function ??

Post by onoehring » 2020-04-09 07:02

Hi xbox,

I am - as pbötcher - not sure what you want to do.
Did you see, that in the details of your table there is a checkbox which needs to be UNchecked, so you will get a button "Save as copy"?
Untitled.png
Untitled.png (57.62 KiB) Viewed 6461 times
Olaf

xbox2007
Veteran Member
Posts: 129
Joined: 2016-12-16 16:49

Re: where is Save As Copy Function ??

Post by xbox2007 » 2020-04-09 10:48

thanks a lot onoehring
this is Save As Copy Function
before Press Save As Copy
Image
After Press Save As Copy
Image

i want when press Save As copy
run sql statement to insert information into membership_users

for Ex. ( this another table ) only example

Code: Select all

	function test_after_update($data, $memberInfo, &$args){
	$memberID	= $data['Name'];
	$userID = sqlValue("SELECT memberID FROM membership_users where custom3 ='{$memberID}' LIMIT 1");
	set_record_owner('test', $data['selectedID'], $userID);
thanks a lot

User avatar
onoehring
AppGini Super Hero
AppGini Super Hero
Posts: 1156
Joined: 2019-05-21 22:42
Location: Germany
Contact:

Re: where is Save As Copy Function ??

Post by onoehring » 2020-04-09 10:59

Hi,

it seems like this is the copy function you wanted. If so, great ... but what do you want with the SQL?
I do not understand. You get the copy and the record owner should change? Isn't this done automatically?
Why does the code you provided does not work for you - if you want to set the owner of the copied record to the current person?

Sorry, so many questions. Please try to be more precise what you have, what you want to do, and what should be the result afterwards. I would think, this will help everyone.

Olaf

xbox2007
Veteran Member
Posts: 129
Joined: 2016-12-16 16:49

Re: where is Save As Copy Function ??

Post by xbox2007 » 2020-04-09 11:10

thanks for your replay

I do not understand. You get the copy and the record owner should change? Isn't this done automatically?

i want set owner for client so he can see only has record
for ex . Johnny English is client name , he have user name johnny in my app

when he login he can see has record only

also i want run other sql statement to insert the data into another table
like this

Code: Select all

sql("INSERT INTO `membership_users` set memberID='{$memberID}', passMD5='" . password_hash($password, PASSWORD_DEFAULT) . "', email='{$email}', signupDate='" . @date('Y-m-d') . "', groupID = 5, isBanned= 0, isApproved= 1 , custom1='{$Name}' , custom3='{$CustomerID}'", $eo);

User avatar
onoehring
AppGini Super Hero
AppGini Super Hero
Posts: 1156
Joined: 2019-05-21 22:42
Location: Germany
Contact:

Re: where is Save As Copy Function ??

Post by onoehring » 2020-04-09 11:17

Hi,

can't you use the AG built in method? Each user is in a group (or define permissions based on users - I would not recommend that).
Go to the admin area -> groups and define to your needs:
ec20200409_01.png
ec20200409_01.png (28.42 KiB) Viewed 6449 times
The user would only be able to see his/her own records.

What is the problem "running another SQL statement"? As pbötcher described, just use the hook function you need, e.g. _after_update

Olaf

xbox2007
Veteran Member
Posts: 129
Joined: 2016-12-16 16:49

Re: where is Save As Copy Function ??

Post by xbox2007 » 2020-04-09 12:20

thnaks for your replay

i already know this one and this will set record for who create the record
but in my case
i give owner for other user ( he cannot create or update any record )

User avatar
onoehring
AppGini Super Hero
AppGini Super Hero
Posts: 1156
Joined: 2019-05-21 22:42
Location: Germany
Contact:

Re: where is Save As Copy Function ??

Post by onoehring » 2020-04-09 13:49

Hi,

and what is your problem then? Just read the username of the to-be-owner and set the record owner like you suggested yourself in the after_insert. The problem I see here is, that this function is called _before_ executing the ownership insert query.
My suggestion for this is,
a) check which hook to use in the first place
b) see what is specific on the "save copy" command (from the regular save command)
c) when a copy is being executed, write something to a session variable - the new ID probably
d) get this session variable in the _init function of the table. If it's set, execute your setowner function

What I still do not understand is: Why copy a record (initiated by user X as it seems if user X can not create/edit any records)... I am not so sure, if your database design is without error, e.g. normalized.

Olaf

xbox2007
Veteran Member
Posts: 129
Joined: 2016-12-16 16:49

Re: where is Save As Copy Function ??

Post by xbox2007 » 2020-04-09 16:30

What I still do not understand is: Why copy a record (initiated by user X as it seems if user X can not create/edit any records)... I am not so sure, if your database design is without error, e.g. normalized.
X user is customer --- he should only see record but he cannot (Add / Edit / Save ) any information this why i give he owner for has records

already use tablename_after_update() to insert date to other tables for run some SQL Query it work fine

but i want once user press Save As Copy App with do
1- create new record in Table
2- run some SQL Query like tablename_after_update()

** why in Hooks there is no Save As Copy Function like (( tablename_after_update() ))

thanks a lot

User avatar
onoehring
AppGini Super Hero
AppGini Super Hero
Posts: 1156
Joined: 2019-05-21 22:42
Location: Germany
Contact:

Re: where is Save As Copy Function ??

Post by onoehring » 2020-04-09 16:36

Hi,

** -> probably because this is simply an "insert" of a new record. Check the _after_insert function if this is used when saving a copy.

Then, you will be able to set a new owner (make sure the owner is set (=corrected to your needs) after Appgini itself set's the owner).
I still don't understand why you don't write the code to do what you want. Sorry.

Olaf

xbox2007
Veteran Member
Posts: 129
Joined: 2016-12-16 16:49

Re: where is Save As Copy Function ??

Post by xbox2007 » 2020-04-09 16:55

hi , thanks again

_after_insert function will run MySQL Query once user press Save Now if its new record

*** Save As Copy will use _after_insert function if not new record ***

but if i add MySQL Query with _after_insert function will run MySQL Query two times
one time when press Save Now or save . and when user press Save As Copy will run MySQL Query

i have many MySQL Query want run after Save As Copy not only change owner query

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1635
Joined: 2018-04-01 10:12

Re: where is Save As Copy Function ??

Post by pbottcher » 2020-04-09 22:15

Hi,

when you use the "save as Copy" button this is treated like if you would create a complete new record. So the before_insert and after_insert hooks are used.

I still do not get what you try to do and where your problem is.
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

User avatar
onoehring
AppGini Super Hero
AppGini Super Hero
Posts: 1156
Joined: 2019-05-21 22:42
Location: Germany
Contact:

Re: where is Save As Copy Function ??

Post by onoehring » 2020-04-10 06:23

Hi xbox,

I am in line with pbötcher: I also do not understand what your problem is / what you want to do.

Olaf

xbox2007
Veteran Member
Posts: 129
Joined: 2016-12-16 16:49

Re: where is Save As Copy Function ??

Post by xbox2007 » 2020-04-10 16:11

i have app there are table some information on table no change ( no need to change ) only there two record on row need to update and after update insert on new row
on this photo ,,,,, record name is not change ,,,, ( Action and mmmm ) is change
Image

after change Action and mmmm and press Save As copy
Image

now everything fine no problem

i want when press on Save As Copy run SOME SQL Query or send email or any other action
like we do with
tablename_after_insert
or
tablename_after_update

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1635
Joined: 2018-04-01 10:12

Re: where is Save As Copy Function ??

Post by pbottcher » 2020-04-10 16:16

ok,

but still, what is your problem. When you hit "Save as Copy" the _before_insert and after_insert hooks are triggered, so you can add you code there and do what you need to do.
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

xbox2007
Veteran Member
Posts: 129
Joined: 2016-12-16 16:49

Re: where is Save As Copy Function ??

Post by xbox2007 » 2020-04-10 16:23

if i add code _before_insert will not working because the row already create
if i add code _after_insert will run SQl Query when press Save Now or Save and SQl Query will run also when press Save As Copy

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1635
Joined: 2018-04-01 10:12

Re: where is Save As Copy Function ??

Post by pbottcher » 2020-04-10 16:33

Hi,

sorry I still not get your problem. I think you missunderstand the Save as Copy feature.

This feature is meant to reduce typing of information. So you can reuse information you already entered in the form and only adopt some information.

BUT !!!

At the end it is just treated the same way as if you would enter a complete new record.
So there is NO difference if you enter a new record, or if you hit "Save as Copy".

If you would expain what you try to do it would be helpful. If you just say you want to run some SQL, why can't you just add it?
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

xbox2007
Veteran Member
Posts: 129
Joined: 2016-12-16 16:49

Re: where is Save As Copy Function ??

Post by xbox2007 » 2020-04-10 16:44

Save as Copy function , as i know
its make copy for row and add new row in table
Image
please check photo

you will see ID = 1 , name = Johnny English , Action = Found , Mmmm = 01/04/2020
simply i change - Action = Not Found , Mmmm = 09/04/2020
then press Save As copy
i get new row ID = 2 , name = Johnny English , Action = Not Found , Mmmm = 09/04/2020

this is very simple and there is no any problem with that .

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1635
Joined: 2018-04-01 10:12

Re: where is Save As Copy Function ??

Post by pbottcher » 2020-04-10 17:17

Yes that is the meaning, but what is your question ?
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

xbox2007
Veteran Member
Posts: 129
Joined: 2016-12-16 16:49

Re: where is Save As Copy Function ??

Post by xbox2007 » 2020-04-10 17:53

now we understand Save As copy function

i want when press on Save As Copy ,,, run ( Some MySQL Query or Send email ) same what we do with
tablename_after_insert
or
tablename_after_update

its possible or not ????

Post Reply