Вы находитесь на странице: 1из 15

Orden de ejecucin de

reglas y frmulas

Orden de ejecucin de
reglas y frmulas
Transaccin "Invoice"
InvoiceId*
InvoiceDate
CustomerId
CustomerTotalPurchases
CategoryDiscount
InvoiceDiscount
= InvoiceSubTotal *CategoryDiscount
InvoiceShippingCharge = Max( ShippingDate, ShippingDate
<=InvoiceDate,,ShippingCharge)
InvoiceSubTotal
= SUM( InvoiceDetailAmount )
InvoiceTotal
= InvoiceSubTotal InvoiceDiscount
+ InvoiceShippingCharge
(ProductId*
ProductPrice
ProductStock
InvoiceDetailQuantity
InvoiceDetailAmount) = InvoiceDetailQuantity *
ProductPrice

Reglas:

Add( InvoiceTotal, CustomerTotalPurchases);


Error( Insufficient Stock ) if ProductStock<0;
Subtract( InvoiceDetailQuantity, ProductStock);

Customer

CustomerId*
CustomerName
CategoryId
CustomerTotalPurchases

Category

CategoryId*
CategoryDiscount

Shipping

ShippingDate*
ShippingCharge

Product

ProductId*
ProductPrice
ProducStock

rbol de evaluacin

R. Add(InvoiceTotal, CustomerTotalPurchases);
F. InvoiceTotal = InvoiceSubTotal - InvoiceDiscount +
InvoiceShippingCharge
CustomerTotalPurchases
F. InvoiceDiscount = InvoiceSubTotal*CategoryDiscount
F. InvoiceShippingCharge = MAX( ShippingDate, ShippingDate <=
InvoiceDate,,ShippingCharge)
F. InvoiceSubTotal = SUM( InvoiceDetailAmount )
F. InvoiceDetailAmount = InvoiceDetailQuantity *ProductPrice
InvoiceTotal
R. Subtract(InvoiceDetailQuantity, ProductStock) ;
R. Error( Insuffcient Stock) if ProductStock < 0 ;

InvoiceDiscount
InvoiceShippingChar
ge

error (Insufficient Stock )


InvoiceSubTotal

ShippingDate

ProductStock InvoiceDetailAmount CategoryDiscount

InvoiceDetailQuantity

ProductPrice

InvoiceDate

ShippingCharge

Alteraciones del orden de disparo


de las reglas
Error

Total
Calculad
o

Total
Ingresado

SupplierId*
InvoiceId*
...
InvoiceDetailAmount
InvoiceEntTotal
Entered Total
( ProductId*
InvoiceDetailQuantity
InvoiceDetailPrice
InvoiceDetailAmount = InvoiceDetailPrice * InvoiceDetailQuantity)
...
InvoiceCalcTotal = SUM(InvoiceDetailAmount) Calculated Total
Error(The calculated total doesnt match with the entered total') if
(InvoiceEntTotal<>InvoiceCalcTotal) On AfterLevel Level ProductId;

Eventos de disparo
La mayora de las reglas de transacciones permiten que se les
agregue de ser necesario un evento o momento de disparo.
Al agregar un evento o momento de disparo a una regla,
estaremos especificando que la regla se deber ejecutar en ese
determinado momento.
Eventos de disparo:

BeforeValidate
AfterValidate
BeforeInsert, BeforeUpdate, BeforeDelete
AfterInsert, AfterUpdate, AfterDelete
AfterLevel
BeforeComplete
AfterComplete

Ejemplo en transaccin de 2 niveles


Interactivamente y antes de confirmar:

REGLAS STAND-ALONE

EVALUACION DE REGLAS
Y
FORMULAS SEGN
ARBOL

PARA CADA
LINEA
EVALUACION DE
REGLAS Y
FORMULAS
SEGN ARBOL

Ejemplo en transaccin de 2 niveles


Al confirmar los datos, se ejecutan en el siguiente orden:

REGLAS STAND-ALONE
EVALUACION REGLAS Y FRMULAS SEGN
ARBOL
BeforeValidate
VALIDACIN
AfterValidate / BeforeInsert / Update / Delete
GRABACION DEL
CABEZAL / Update / Delete
AfterInsert
EVALUACION DE REGLAS
PARA
Y
CADA
FORMULAS SEGN
LINEA
BeforeValidate
ARBOL
VALIDACIN
AfterValidate / BeforeInsert / Udpate /
Delete
GRABACION DE LA LINEA
AfterInsert/Update/Del
ete
ABANDONAR NIVEL 2
AfterLevel Level attNivel2 BeforeComplete
COMMIT
AfterComplete

Ejemplos
Cundo se dispararn las siguientes reglas?
Something.call( InvoiceId ) if Insert;
Luego de validado el campo InvoiceId e inferido que se est en modo Insert

Something.call( InvoiceId ) on BeforeInsert;


Luego de disparadas todas las reglas y frmulas segn rbol, y validados
todos los datos del cabezal. Un instante antes de insertar el registro.

Something.call( InvoiceId, ProductId ) on BeforeInsert;


Luego de disparadas todas las reglas y frmulas segn rbol, y validados
todos los datos de la lnea. Un instante antes de insertar el registro.

Something.call( InvoiceId ) on BeforeInsert Level ProductId;


dem que el anterior. Observar que Level ProductId especifica que se est
hablando del BeforeInsert de las lneas y no del cabezal.

Ejemplos
Algunas reglas estn mal programadas. Cules?
InvoiceDate = &today on AfterInsert;
Incorrecto: El ltimo momento para asignar valor a un atributo del cabezal
es inmediatamente antes de su grabacin (BeforeInsert)

Something.call( InvoiceDate ) on AfterInsert;


Correcto: aqu se est pasando el valor de un atributo del cabezal; mientras
se est en la instancia de la factura se tiene ese valor en memoria. ltimo
momento posible para utilizarlo AfterComplete.

Something.call( InvoiceId, ProductId ) on AfterLevel Level ProductId;


Incorrecto: la regla, sin el evento de disparo est asociada al 2do. Nivel, es
decir, se disparara por cada lnea. Pero el evento de disparo la condiciona a
ejecutarse al salir de las lneas. Qu valor tendra ProductId?

Reglas con el mismo


evento de disparo
Son disparadas en el orden en que fueron definidas
Ejemplo 1
xxx.call() On AfterComplete;
yyy.call() On AfterComplete;

Ejemplo 2
pgmname.call( CustomerId, &flag) On AfterComplete;
error('
') if &flag = 'N On AfterComplete;

Eventos en Transacciones

Eventos en Transacciones
Evento Start
Evento User Event
Evento After Trn
Evento Exit
Evento TrackContext

Eventos Start
Start: Se ejecuta cada vez que se somete el
form de una transaccin al servidor.
SINTAXIS: Event Start
cdigo
EndEvent

EJEMPLO: Event Start


&entrada=Now()
EndEvent

Eventos de Usuario
Adems de los eventos ofrecidos por GeneXus, el analista puede
definir eventos creados por l, llamados eventos de usuario.
Propiedades

Web:

Orden de
ejecucin

1. Evento Start
2. Lectura de atributos y variables del form
3. Evento de usuario seleccionado

Evento After Trn


Ocurre inmediatamente despus de la ejecucin de las reglas
con evento de disparo AfterComplete.
Sintaxis:

Ejemplo:

Event After Trn


cdigo
Endevent

Event After trn


Return
EndEvent

Вам также может понравиться