Schema Trigger Example PLEASE!!

jmhrivnak

New Member
Hi All,

I've been trying to utilizet his whole trigger functionality for a couple weeks now and haven't been able to do anything other than have a message window pop up. Would someone please post an example of a trigger that maybe sets a few default values for other fields or calculates some field values. I would really really appreciate any help anyone could give me in this area.

Thank you very much.

-John Hrivnak
(303) 288-7873 Ext. 226
johnmh@hydrogate.com
 
Hi,

Here is a very simple trigger procedure:

TRIGGER Procedure for CREATE of mytable.
ASSIGN mytable.rec-id = next-value(mytable_seq).

When you create a record in table mytable it automatically assigns the rec-id field using the next sequence value.


Regards,
Gabor
 

drsymix

New Member
SL5/6 Design Triggers

I read another reply you gave noticed you where on SL5+.

If you can trigger this event on a GUI maintenance screen, you may choose to use a entry or leave trigger. You can make this change clicking Design Button and selecting Triggers tab.

This will allow you to simply recompile on upgrades.

However, if you choose a db trigger, take into consideration that you must make sure trigger gets carried forward on upgrades. Many other downsides exist for db triggers. Vantage (DCD) was full of them and it was a nightmare.

I have included examples of both.

Good luck.

A. Entry/Leave Trigger (search help on trig-def).

Launches a custom program when you enter a screen-object. The trigger is a custom program written by the user or developer for a specific purpose, for example, setting default values, validating fields, confirming changes, or prompting for additional information when a user enters a field. After selecting the Override Default toggle-box, enter a program which will activate when you enter a screen-object.
EXAMPLE 1:

{lib/trig-def.i &object=cs/v-coitem}
IF coitem.item BEGINS "Widget"
AND coitem.qty-ordered-conv > 100 THEN DO:

MESSAGE "You may order only 100 Widgets!".
coitem.qty-ordered-conv = 100.0.

END.

EXAMPLE 2:

{lib/trig-def.i &object=item/v-itmhdr}

IF item.item BEGINS "Bolt" THEN

/* All Bolts have the same basic characteristics: */
ASSIGN

item.u-m = "EA"
item.product-code = "PP"
item.backflush = YES
item.bflush-loc = "PUR-1"

p-auto-save = YES.

Copyright © 2000 Symix Systems, Inc.


B. DB Trigger (Jobmatl Audit)

TRIGGER PROCEDURE FOR WRITE OF jobmatl OLD BUFFER old-jobmatl.

/* Procedure: triggers/jobmatl/update.p
*
* Revision XXXXXXXXXXXXXXXXXXXX
* XXXXXXXXXXXXXXXXXXXXXXXXXXX
*
*/

def new global shared var call-var as char.
def shared var call-var as char.

def var tz-audit-action like z-audmtl.audit-action init "A".
def var tz-audit-seq like z-audmtl.audit-seq init "1".

if jobmatl.item <> old-jobmatl.item or
jobmatl.matl-qty <> old-jobmatl.matl-qty then do:

find last z-audmtl no-lock where
z-audmtl.job = jobmatl.job and
z-audmtl.suffix = jobmatl.suffix and
z-audmtl.oper-num = jobmatl.oper-num and
z-audmtl.sequence = jobmatl.sequence no-error.
if avail z-audmtl then
assign
tz-audit-action = "U"
tz-audit-seq = z-audmtl.audit-seq + 1.

create z-audmtl.
assign
z-audmtl.job = jobmatl.job
z-audmtl.suffix = jobmatl.suffix
z-audmtl.oper-num = jobmatl.oper-num
z-audmtl.sequence = jobmatl.sequence
z-audmtl.audit-seq = tz-audit-seq
z-audmtl.audit-date = today
z-audmtl.audit-time = time
z-audmtl.audit-user = caps(call-var)
z-audmtl.audit-action = tz-audit-action
z-audmtl.audit-prog = "JOBMATL"
z-audmtl.item = jobmatl.item
z-audmtl.matl-qty = jobmatl.matl-qty
.
release z-audmtl.
end.

/* EOF */
 

jmhrivnak

New Member
Hi Folks... thanks for helping out.

I think I'm getting my triggers to do what I need however when I ASSIGN values to ux-coitem fields the values show up if I query the table but are not displayed on the Order Line Maintenance screen where I have added the fields. This is the code I'm using... please point out any inefficiency and share any insight into the 'invisible values' issue. The messages are just in as indicators to let me know values have changed. Thank you very much!

-John

TRIGGER PROCEDURE FOR ASSIGN OF test.ux-co.uf-co-sub-due.

FIND CURRENT ux-co EXCLUSIVE-LOCK NO-ERROR.
IF NOT AVAILABLE ux-co THEN DO:
MESSAGE "ERROR CANNOT CONTINUE" VIEW-AS ALERT-BOX ERROR.
RETURN NO-APPLY.
END. ELSE DO:

FOR EACH test.coitem WHERE coitem.co-num = ux-co.co-num.
FIND test.ux-coitem WHERE ux-coitem.co-num = coitem.co-num
AND ux-coitem.co-line = coitem.co-line
AND ux-coitem.co-release = coitem.co-release
EXCLUSIVE-LOCK NO-ERROR.
IF NOT AVAILABLE ux-coitem THEN DO:
MESSAGE "ERROR CANNOT CONTINUE" VIEW-AS ALERT-BOX ERROR.
RETURN NO-APPLY.
END. ELSE DO:
ASSIGN ux-coitem.uf-coitem-sub-due = ux-co.uf-co-sub-due.
MESSAGE "Order:" ux-co.co-num "Line:" ux-coitem.co-line "Submit by:"
ux-coitem.uf-coitem-sub-due.
END.
END.

MESSAGE "The date " ux-co.uf-co-sub-due " has been assigned.".

END.
 

jmhrivnak

New Member
more info

A little more info on what I am trying to accomplish...

I have added a 'submit by' field on both the Order Maint and Order Line Detail screens.

ux-co.uf-co-sub-due & ux-coitem.uf-coitem-sub-due.

on assign of ux-co.uf-co-sub-due on Order Maint I want the trigger to change the value for ux-coitem.uf-coitem-sub-due on all the order lines of the current order to ux-co.uf-co-sub-due.

As I side in my last post the assignment of values on the lines seems to be working but the Order Line Detail screen which ux-coitem.uf-coitem-sub-due appears on doesn't display the value.

THanks again.

-John
 

jmhrivnak

New Member
Still stuck on this... can't figure out why the values change in the table but do not show up on the Order Maintenance Screen where they have been added as UET Fields.

The problem does however seem to be specific to fields with date values.
 
U

Unregistered

Guest
This may be way off base but I thought I'd through it out there any way. Once you have assigned the value
for ux-coitem.uf-coitem-sub-due are you re-displaying each line?

Example:

ASSIGN
ux-coitem.uf-coitem-sub-due = ux-co.uf-co-sub-due.

DISPLAY ux-coitem.uf-coitem-sub-due
IN FRAME {&FRAME-NAME}.
 

jmhrivnak

New Member
I read that K-base article and honestly it was a little over my head. From what I understand from the article and from Gabor's message, is that I may be seeing data from an older buffer or record.(?)

When I run my trigger it does populate the table with the new information. That being true wouldn't I see those values the next time I started up a session? Also, only date values are not displaying, wouldn't ALL of the changed fields refer to an older buffer/record if this was the case?

Unfortunately, my knowledge of buffers and a lot of what happens in the background is VERY limited as is my knowledge of frames. SO, if you can confirm or deny my suspicions I would really appreciate it.

I have not added the DISPLAY...{&FRAME-NAME} bit because I don't know what the frame name is... this is all define by syteline as far as I know and I don't have source code. Is there a way to identify the current frame name programmatically so that I can use this Display statement? OR does anyone know the FRAME-NAME for the Order Line Detail screen in Syteline?

Thanks to all.
 

jmhrivnak

New Member
Entry/Leave Triggers

By the way...

I have tried to use the Field Entry/Leave triggers but for some reason the include files can't find the subsequent procedures that they reference. I assumed that the Pro-Path etc... would handle that but apperently it isn't working that way for some reason. Is there a way to include the PATH in the call to {lib...} or is there some issue I should investigate regarding my propath or something else to resolve this issue?


OH! And should the code I included above have some reference to a buffer? and if so, how do I identify the name of the buffer that is being used?

Thanks again!
 
U

Unregistered

Guest
UF-COITEM-SUB-DUE NOT REDISPLAYING

Is the field being displayed in the order line maintenance coming from the ux-coitem file or is it a variable that has been defined? If it's the variable then just verify that the value is getting reassigned.
 

jmhrivnak

New Member
Date problem addition

Hi All,

I went into the design view and adjusted the actual screen size of the field ux-xoitem.uf-coitem-sub-due which I have added to the Order Line Detail screen. When I saved the design changes the date value DID actually show up! When I switch to another line and come back however it is no longer there! Perhaps this lends some weight to the knowledge base issue Gabor has suggested. Thoughts anyone? Please?

Thanks again.

-John
 

jmhrivnak

New Member
OK

I have done some additional test trying to figure out what is causing this problem. I haven't solved the problem but I have added some addition variable types with different graphical representations. I found that the Fill-In type of graphic representation will not display any data type but it still seems to be specific to the Order Line Detail screen. I have a couple combo boxes and check boxes and both of these work perfectly.
 
Top