Skip to Content

if condition not working in e-amil alert gateway pre-send action

Hi Everyone,

CPS version M33.69-61130.

In our gateway pre-send action, i do a check whether the job alert source is for spool files and if yes, i use a different mail format.

So i use the following condition,

Alert            alert           = jcsEmailAlertGatewayPreSendActionContext.getAlert();;AlertSource alertsource = alert.getAlertSource();Strine alertname = alertsource.getName();if ((alertname == "SPOOL_ALERT_FOR_GL_CLOSERECONKEYS") || (alertname == "SPOOL_ALERT_FOR_GL_OILISTFORKEYDATE") || (alertname == "SPOOL_ALERT_FOR_GL_OPENITEMLIST") || (alertname == "SPOOL_ALERT_FOR_GL_OPENITEMSSUMMARY")){Job mail = jcsSession.getJobDefinitionByName("SPOOL_MAIL").prepare()}else{Job mail = jcsSession.getJobDefinitionByName("ALERT_MAIL").prepare();mail.getJobParameterByName("ALERT_NAME").setInValueString(alertname);}

But for some reason, the if condition doesn't work for the spool alert.

As you can see in the following screen cap, the variable alert name perfectly resolves the job alert source name and is reflected in the mail, but is not inside the loop.

Can someone please let me know what am i doing wrong?

Add a comment
10|10000 characters needed characters exceeded

Related questions

3 Answers

  • Best Answer
    Posted on Mar 20, 2013 at 08:11 AM

    Hi Nanda,

    Sorry, I was sleepy ... you are not comparing string values but object references!

    Alert alert = jcsEmailAlertGatewayPreSendActionContext.getAlert();;

    AlertSource alertsource = alert.getAlertSource();

    String alertname = alertsource.getName();

    if ("SPOOL_ALERT_FOR_GL_CLOSERECONKEYS".equals(alertname) || "SPOOL_ALERT_FOR_GL_OILISTFORKEYDATE".equals(alertname) || "SPOOL_ALERT_FOR_GL_OPENITEMLIST".equals(alertname) || "SPOOL_ALERT_FOR_GL_OPENITEMSSUMMARY".equals(alertname))

    {

    Job mail = jcsSession.getJobDefinitionByName("SPOOL_MAIL").prepare();

    }

    else

    {

    Job mail = jcsSession.getJobDefinitionByName("ALERT_MAIL").prepare(); mail.getJobParameterByName("ALERT_NAME").setInValueString(alertname);

    }

    So, you always put the string before the equals, because otherwise you might get an NPE in the very unlikely event where alertname is null.

    So, to compare a string with the value of a variable, you do "my silly string".equals(mySillyVariable).

    Grabbing a cup of coffee.

    Regards,

    HP

    Add a comment
    10|10000 characters needed characters exceeded

    • 😀

      I was just looking at string comparison methods in java, and you posted exactly the one i had in mind.

      Thanks a lot for your quick reply.

      But, I went with contains of method, since it is simpler and better suited.

      if ( alertname.contains("spool"))

      Thanks

      Nanda

  • Posted on Mar 20, 2013 at 07:16 AM

    Hi Nanda,

    Could it be that you specified

    Strine alertname = alertsource.getName();

    instead of

    String alertname = alertsource.getName();

    Notice the misspelled Strine.

    I do not know if it is the mistake, please check.

    Regards,

    HP

    Add a comment
    10|10000 characters needed characters exceeded

    • hi Carpenter,

      sorry i made a typo while creating this question, it is actually written as string alertname only, otherwise, REL error would occur when i try to save.

      My problem is that the code is compiled and executed, there are not syntax problems, but unable to debug step by step and evaluate the if condition.

      the if condition always ends up as false and goes to the else part.

      Please let me know what could be wrong.

      Thanks

      Nanda

  • author's profile photo Former Member
    Former Member
    Posted on May 05, 2014 at 11:22 AM

    Do you know how to take away the spool_ids.txt?

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.