Para nuestra última entrada dedicada a los frameworks de notificación, vamos a hablar del “Notification Framework” el cual nos permite generar correos electrónicos y notificaciones a las listas de trabajo de los usuarios.
Digamos que queremos hacer una notificación que se dispare al momento de modificar o crear un nuevo cliente en nuestra aplicación.
Para lograr lo anterior lo primero que tenemos que hacer es agregar un proceso y una categoría al "Notification Framework". El proceso puede ser CustomerManagement y la categoría UpdateOrCreate. Para crear estos objetos nos dirigimos a Inicio - Componentes de Empresa - Eventos y Notificaciones - Entorno de Notificaciones - Registro de Notificaciones y creamos un registro que se vea como la imagen mostrada a continuación:
Para lograr lo anterior lo primero que tenemos que hacer es agregar un proceso y una categoría al "Notification Framework". El proceso puede ser CustomerManagement y la categoría UpdateOrCreate. Para crear estos objetos nos dirigimos a Inicio - Componentes de Empresa - Eventos y Notificaciones - Entorno de Notificaciones - Registro de Notificaciones y creamos un registro que se vea como la imagen mostrada a continuación:
El siguiente paso es crear el registro de contexto de nuestro proceso. El registro de contexto de un proceso contiene datos que nos permiten identificar los objetos a los que corresponde la notificación, además el registro de contexto de un proceso se puede visualizar en la consola de notificaciones lo cual hace más facil identificar las razones de la notificación.
Todo registro de contexto debe tener como mínimo el subrecord EOEN_LOG_KEY, adicionalmente para nuestro ejemplo vamos a incluir el SETID y el CUST_ID del cliente que está siendo modificado; y el OPRID del usuario que está modificando o creando el cliente. El registro lo llamaremos PE_CUST_CTX.
El registro debe quedar de la siguiente forma
Después de crear el registro de contexto vamos al registro CUSTOMER, al campo SETID y al evento SAVEPOSTCHANGE.
Lo primero que vamos a hacer es importar los paquetes del "Notifications Framework" que vamos a utilizar:
import EOEN_MVC:EOEN_MODEL:*;
Luego vamos a declarar un objeto del tipo EOENInteface que es la clase que nos permite generar las notificaciones.
Local EOEN_MVC:EOEN_MODEL:EOENInterface &oEwnInterface;
A continuación creamos el objeto de tipo EOENInterface para el proceso CustomerManagement que acabamos de crear, el segundo parámetro es una instancia de proceso para la cual generamos un aleatorio (si estamos usando la clase EOENInterface dentro de un app engine podemos utilizar el ProcessInstance como segundo parámetro):
&oEwnInterface = create EOEN_MVC:EOEN_MODEL:EOENInterface("CUSTOMERMANAGEMENT", Int(Rand() * 100000000));
Luego creamos el registro de contexto
Local Record &ContextRec;
&ContextRec = CreateRecord(Record.PE_CUST_CTX);
Asignamos los valores del ContextRecord empezando por el proceso y la categoría; y continuando con los datos adicionales que definimos.
&ContextRec.EOEN_PRCS_NAME.Value = "CUSTOMERMANAGEMENT";
&ContextRec.EOEN_CATEGORY.Value = "UpdateOrCreate";
&ContextRec.SETID.Value =CUSTOMER.SETID.Value;
&ContextRec.CUST_ID.Value =CUSTOMER.CUST_ID.Value;
&ContextRec.OPRID.Value = %OperatorId;Ahora iniciamos la categoría del objeto &oEwnInterface
&oEwnInterface.EOENCategory = "UpdateOrCreate";
Agregamos el Record de contexto al objeto:
&oEwnInterface.AddContextRecord(&ContextRec);
Digamos que queremos notificar al administrador (VP1) vía correo electrónico sobre la modificación o creación del usuario, para lograr esto utilizamos el método AddEmailByOprID.
&oEwnInterface.AddEmailByOprID(%OperatorId);
&oEwnInterface.GenerateEmail( True);
&oEwnInterface.GenerateEmail( True);
Supongamos que también queremos notificar a los usuarios vía lista de trabajo a los miembros del rol "CUST_MANAGERS". Para lo anterior utilizamos el método GenerateWL:
&oEwnInterface.GenerateWL( True, "", "CUST_MANAGERS");
Lo otro que nos permite el "Notification Framework" es definir la URL a la que referencia la notificación, en nuestro caso sería la dirección del componente de clientes para el cliente que fue modificado.
&oEwnInterface.EOENRedirectURL =
GenerateComponentPortalURL("EMPLOYEE", "ERP", MenuName.MAINTAIN_CUSTOMERS, "GBL", Component.CUSTOMER_GENERAL, "" ,"U", CUSTOMER.SETID, CUSTOMER.CUST_ID);
GenerateComponentPortalURL("EMPLOYEE", "ERP", MenuName.MAINTAIN_CUSTOMERS, "GBL", Component.CUSTOMER_GENERAL, "" ,"U", CUSTOMER.SETID, CUSTOMER.CUST_ID);
Por último llamamos el método log para generar la notificación:
Local array of string &ArrayOfBindVals;&ArrayOfBindVals = CreateArray(CUSTOMER.CUST_ID, %OperatorId);
&oEwnInterface.Log(0, 0, "Fue modificado un cliente", &ArrayOfBindVals);
Debemos recordar agregar el rol CUST_MANAGERS a los usuarios a los cuales deseamos les sean notificadas las actualizaciones de los clientes en las listas de trabajo. También debemos recordar asignarle un correo electrónico al usuario VP1.
Luego podemos ir a cualquier cliente y modificarlo, y revisar la notificación por la consola de notificaciones y se verá de la siguiente forma:
Si damos clic en el link de ver contexto el sistema nos mostrará el registro de contexto que agregamos a nuestra notificación
Si damos cliente en el link Ver Detalle Transacción el sistema nos llevará al cliente que fue modificado.
Si ingresamos al sistema con un usuario que pertenezca al rol. CUST_MANAGERS y vamos a la lista de trabajo vamos a encontrar las notificaciones generadas, como se puede ver a continuación:
Está información también la podemos visualizar en el correo del usuario VP1.
Por último si queremos parametrizar el rol al cual queremos notificar, podemos hacer para todo el sistema o por unidad de negocio, para eso vamos a las ruta Inicio - Componentes de Empresa - Eventos y Notificaciones - Entorno de Notificaciones - Modific. Sistema Notificaciones o Modific. UniNeg Notificaciones, y ahí adicionamos un registro para el proceso y categoría que creamos, y asignamos el rol al que queremos notificar y el correo electrónico también.
Bueno espero que podamos poner en práctica estas herramientas de las que hablamos en las últimas 3 semanas y que logren hacer nuestro trabajo más facil y de mejor calidad. Nos vemos la próxima semana nuevamente. Se me olvidaba acá les dejo el código completo:
import EOEN_MVC:EOEN_MODEL:*;
Local EOEN_MVC:EOEN_MODEL:EOENInterface &oEwnInterface;
&oEwnInterface = create EOEN_MVC:EOEN_MODEL:EOENInterface("CUSTOMERMANAGEMENT", Int(Rand() * 100000000));
Local Record &ContextRec;
&ContextRec = CreateRecord(Record.PE_CUST_CTX);
&ContextRec.EOEN_PRCS_NAME.Value = "CUSTOMERMANAGEMENT";
&ContextRec.EOEN_CATEGORY.Value = "UpdateOrCreate";
&ContextRec.SETID.Value = CUSTOMER.SETID.Value;
&ContextRec.CUST_ID.Value = CUSTOMER.CUST_ID.Value;
&ContextRec.OPRID.Value = %OperatorId;
&oEwnInterface.EOENCategory = "UpdateOrCreate";
&oEwnInterface.AddContextRecord(&ContextRec);
rem &oEwnInterface.AddEmailByOprID(%OperatorId);
rem &oEwnInterface.GenerateEmail( True);
&oEwnInterface.GenerateWL( True, "", "CUST_MANAGERS");
&oEwnInterface.EOENRedirectURL = GenerateComponentPortalURL("EMPLOYEE", "ERP", MenuName.MAINTAIN_CUSTOMERS, "GBL", Component.CUSTOMER_GENERAL, "", "U", CUSTOMER.SETID, CUSTOMER.CUST_ID);
Local array of string &ArrayOfBindVals;
&ArrayOfBindVals = CreateArray(CUSTOMER.CUST_ID, %OperatorId);
&oEwnInterface.Log(0, 0, "Fue modificado un cliente", &ArrayOfBindVals);
Local EOEN_MVC:EOEN_MODEL:EOENInterface &oEwnInterface;
&oEwnInterface = create EOEN_MVC:EOEN_MODEL:EOENInterface("CUSTOMERMANAGEMENT", Int(Rand() * 100000000));
Local Record &ContextRec;
&ContextRec = CreateRecord(Record.PE_CUST_CTX);
&ContextRec.EOEN_PRCS_NAME.Value = "CUSTOMERMANAGEMENT";
&ContextRec.EOEN_CATEGORY.Value = "UpdateOrCreate";
&ContextRec.SETID.Value = CUSTOMER.SETID.Value;
&ContextRec.CUST_ID.Value = CUSTOMER.CUST_ID.Value;
&ContextRec.OPRID.Value = %OperatorId;
&oEwnInterface.EOENCategory = "UpdateOrCreate";
&oEwnInterface.AddContextRecord(&ContextRec);
rem &oEwnInterface.AddEmailByOprID(%OperatorId);
rem &oEwnInterface.GenerateEmail( True);
&oEwnInterface.GenerateWL( True, "", "CUST_MANAGERS");
&oEwnInterface.EOENRedirectURL = GenerateComponentPortalURL("EMPLOYEE", "ERP", MenuName.MAINTAIN_CUSTOMERS, "GBL", Component.CUSTOMER_GENERAL, "", "U", CUSTOMER.SETID, CUSTOMER.CUST_ID);
Local array of string &ArrayOfBindVals;
&ArrayOfBindVals = CreateArray(CUSTOMER.CUST_ID, %OperatorId);
&oEwnInterface.Log(0, 0, "Fue modificado un cliente", &ArrayOfBindVals);



Excelente ! Att: DAPM.
ResponderEliminarUSTED ES UN MAESTRO DOCTOR, GRACIAS POR COMPARTIR ESTOS TUTOS !!! OJALA SIGA SUBIENDO MAS !!! SALUDOS !!!
ResponderEliminar