Wednesday, 9 July 2014

Check if a new record is inserted or copied

 
Situation
The DAL is as much as possible decoupled from the user Interface. Obviously, the DAL knows if a record is being added, changed or deleted. If a record is added, it might sometimes be very useful to know if this new record is being copied from another one.
 
Solution
  A tools function is available to check if a new record is inserted or copied. The syntax is as follows: function boolean dal.is.copy.active()  
 
You can use this function in all field hooks and in the after.new.object(), before.save.object() and after.save.object() hook of the DAL. Note that you should only use this function if mode is DAL_NEW.
If the function returns false, a normal insert is done.
If the function returns true, a dal.copy.object() has been done or the 4GL engine is handling the choice DUPL.OCCUR or GLOBAL.COPY.
 
 
Example function extern long before.save.object(long mode)
{
on case mode
case DAL_NEW:
if dal.is.copy.active() then
|** Record is being copied, also copy children
if copy.children() <> 0 then
return(DALHOOKERROR)
endif
else
|** Record is new ...
endif
break
case DAL_UPDATE:
break
endcase
return(0)
}  
 
TIV
This function is available from TIV level 1801 and higher.
 
 

No comments:

Post a Comment