cancel
Showing results for 
Search instead for 
Did you mean: 

Script to send mail notifications

Former Member
0 Kudos

Hi experts!

I've been asked to send an email to a certain group of users whenever a certain date from an Agreement extension is about to end.

My question is the following:

How can I achieve this via BeanShell Script? (If is achievable trough scripting) The biggest question that I have is to tell the script to know when the date is about to end, because I think it is a script that needs to be running every certain amount of time (or daily) to check the date status, and if the date is about to end then to send the mail.

What kind of objects should I reference to achieve this?

Thanks in advance.

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Kudos

Well I managed to know how to solve the problem.

I created a Explicit Script, and I'm running it from a programmed task.

But it is not working, I assume the problem resides on the script.

Here it is:

import java.text.DateFormat;

import java.text.SimpleDateFormat;

import java.text.ParseException;

import java.util.*;

filterPrompts = new HashMap();

queryExec = IapiQueryExecFactory.createQueryExec(session, "OBTENERFECHASDEGARANTIAS");

paramSet= queryExec.getParameterSet(session,  "OBTENERFECHASDEGARANTIAS");

resultSet = queryExec.execute(filterPrompts);

try {

resultSet = queryExec.execute(filterPrompts);

metaData = resultSet.getMetaData();

Date fechaActual = new Date();

while (resultSet.next()) {

  nombreContrato = resultSet.getString(0);

  fechaFin = resultSet.getString(1);

   nombreProveedor = resultSet.getString(2);

  tipoGarantia = resultSet.getString(3);

  SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

  Date parsedFechaFinal = format.parse(fechaFin);

  if(fechaActual.before(parsedFechaFinal)){

   Properties params = new Properties();

   params.put(new String("TOKEN1"), nombreContrato);

   params.put(new String("TOKEN2"), nombreProveedor);

    params.put(new String("TOKEN3"), tipoGarantia);

   params.put(new String("TOKEN4"), fechaFin);

   String[] recipients = {"somemail@mail.com"};

    sender = session.getAccount();

   mailTypeEnum = new MailTypeEnumType(MailTypeEnumType.NOTIF_GARANTIA);

   NotificationUtil.sendNotification(recipients,sender, mailTypeEnum,params,null,null);

  }

}

}catch(ApplicationException ae) {

}finally {

if(resultSet != null) {   

                        resultSet.close();

    }

}

Can you help me know if there is an actual problem in the script? Kind regards!