DSSendmail subroutine to send notifications

A forum for discussing DataStage<sup>®</sup> basics. If you're not sure where your question goes, start here.

Moderators: chulett, rschirm, roy

Post Reply
abilashkreddy
Participant
Posts: 20
Joined: Thu Nov 16, 2006 1:32 pm
Location: louisville

DSSendmail subroutine to send notifications

Post by abilashkreddy »

Can I know what is the code I have to write using before/after subroutine for DSSendmail such that I can get notifications only when the job aborts or when the job has warnings instead of notifying me when the job runs successfully

Thanks in advance
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Check the INTERIM status of the job. Why not use a Sequence job for this, handle it with the Notification stage and the appropriate triggers?
-craig

"You can never have too many knives" -- Logan Nine Fingers
abilashkreddy
Participant
Posts: 20
Joined: Thu Nov 16, 2006 1:32 pm
Location: louisville

Post by abilashkreddy »

We have plug-ins connected to the server jobs as inputs and outputs that are not supported by the job sequence. So, when I was looking for a way to send email notifications, I found the option, DSSendmail before/after subroutines and it was giving notifications for both successful jobs and unsuccessful jobs. But what I wanted was to send a notification for warnings and aborted jobs.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Ok, two things.

1) Check the INTERIM status of the job after job, that will allow you to decide if an email should go out or not. Keep in mind the fact that an Aborted job won't be able to send emails, only one with warnings will. A Sequence job would solve that 'problem'.

2) I know you've mentioned your issue with Sequence jobs and 'plug-ins not supported' but you are under some serious misunderstandings about how Sequence jobs work. There's no such thing as 'plug-ins connected to the server jobs as inputs and outputs that are not supported by the job sequence'. :?

But let's stick to the subject at hand. Check the INTERIM status using the DSGetJobInfo function.
-craig

"You can never have too many knives" -- Logan Nine Fingers
abilashkreddy
Participant
Posts: 20
Joined: Thu Nov 16, 2006 1:32 pm
Location: louisville

Post by abilashkreddy »

I have written this routine. This is compiling without any errors, but is not sending any mail notifications. Can I know where it might have been wrong

$INCLUDE DSINCLUDE JOBCONTROL.H

call DSLogInfo("In SendMail Routine", "SendMail1");

Sender = Field(InputArg,';',1)
Receiver = Field(InputArg,';',2)
FileName = Field(InputArg,';',3)


JobHandle = DSJ.ME
JobName = DSGetJobInfo(JobHandle,DSJ.JOBNAME)

call DSLogInfo("In SendMail Routine":JobName, "SendMail1");

J3stat = DSGetJobInfo(JobName,DSJ.DSJOBSTATUS);

call DSLogInfo("In SendMail status First":J3stat, "SendMail1");

J1stat = DSGetJobInfo(JobName,DSJ.DSJOBINTERIMSTATUS);

call DSLogInfo("In SendMail status Second":J1stat, "SendMail1");

If J3stat = DSJS.RUNWARN OR J3stat = DSJS.RUNFAILED Then
Line1="Job Failed or completed with warnings"
call DSLogInfo("In SendMail IF":J3stat, "SendMail1");
Reply = DSSendMail(InputArg)
End
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

"J3stat" will never be anything other than RUNNING because that is the job's current status. Why do you check the interim status as requested and then do nothing with it? Check J1stat to decide when to send an email.

I've said this before and I'm going to say it again - the job's status will never be RUNFAILED as aborted jobs just fall over dead, they won't stop and send an email first.
-craig

"You can never have too many knives" -- Logan Nine Fingers
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

I think the problem is that no email is being sent. They can resolve the "always running" issue once they can receive email that the job is running.

Take a look at the DSSendMailTester routine, and see how it's done there. Then try to emulate that. I don't think three arguments in the InputArg are enough, and I don't believe ";" is acceptable as a delimiter - I think it has to be a newline or a field mark.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
abilashkreddy
Participant
Posts: 20
Joined: Thu Nov 16, 2006 1:32 pm
Location: louisville

Post by abilashkreddy »

I am able to compile the routine and after running the job, I am geting an email notification when a job runs successfully. What are the changes that I have make such that I get notification only when a job has warnings.

$INCLUDE DSINCLUDE JOBCONTROL.H

Reply = DSSendMail(InputArg)

call DSLogInfo("In SendMail1 Routine", "SendMail1");


Sender = Field(InputArg,';',1)
Receiver = Field(InputArg,';',2)
FileName = Field(InputArg,';',3)

ErrorCode = 0 ;* set this to non-zero to stop the stage/job

JobHandle = DSJ.ME
JobName = DSGetJobInfo(JobHandle,DSJ.JOBNAME)
call DSLogInfo("In SendMail1 Routine":JobName, "SendMail");
J1stat = DSGetJobInfo(JobName,DSJ.JOBINTERIMSTATUS);

call DSLogInfo("In SendMail status Second":J1stat, "SendMail");

If J1stat = DSJS.RUNWARN or J1stat = 2 Then

Line1="Job Failed or completed with warnings"
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

You actually have to call DSSendMail after determining the status.

Please delete your other post which covers identical ground.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
abilashkreddy
Participant
Posts: 20
Joined: Thu Nov 16, 2006 1:32 pm
Location: louisville

Post by abilashkreddy »

I am getting an email notfication message as

STATUS REPORT FOR JOB: SAPWorkCenterLoad
Generated: 2007-05-22 16:16:17
Job start time=2007-05-22 16:15:31
Job end time=2007-05-22 16:16:17
Job elapsed time=00:00:46
Job status=1 (Finished OK)

when changed the SendMail routine to

$INCLUDE DSINCLUDE JOBCONTROL.H

Reply = DSSendMail(InputArg)

call DSLogInfo("In SendMail1 Routine", "SendMail1");


Sender = Field(InputArg,';',1)
Receiver = Field(InputArg,';',2)
FileName = Field(InputArg,';',3)

ErrorCode = 0 ;* set this to non-zero to stop the stage/job

JobHandle = DSJ.ME
JobName = DSGetJobInfo(JobHandle,DSJ.JOBNAME)
call DSLogInfo("In SendMail1 Routine":JobName, "DSSendMail");
J1stat = DSGetJobInfo(JobName,DSJ.JOBINTERIMSTATUS);

call DSLogInfo("In SendMail status Second":J1stat, "DSSendMail");

If J1stat = DSJS.RUNWARN or J1stat = 2 Then

Line1="Job Failed or completed with warnings"

End
abilashkreddy
Participant
Posts: 20
Joined: Thu Nov 16, 2006 1:32 pm
Location: louisville

Post by abilashkreddy »

What I wanted was no notification when a job runs successfully. But since it is sending an email for a successful run, what should I changes should I make in the above routine such that it gives out notification only when there are warnings
abilashkreddy
Participant
Posts: 20
Joined: Thu Nov 16, 2006 1:32 pm
Location: louisville

Post by abilashkreddy »

The after-job subroutine which I created is running the jobs in the master job twice. Can anyone tell me how to make sure only the job runs once and looks for the status. This subroutine is used in the transformer of the master job

$INCLUDE DSINCLUDE JOBCONTROL.H

call DSLogInfo("In SendMailForWarnings Routine", "DSSendMail")

EmailDetails= Field(InputArg,';',1)
JobName = Field(InputArg,';',2)

call DSLogInfo("In SendMailForWarnings Routine :":EmailDetails, "DSSendMail")
call DSLogInfo("In SendMailForWarnings Routine :":JobName, "DSSendMail")

ErrorCode = 0 ;* set this to non-zero to stop the stage/job



JobHandle=DSAttachJob(JobName, DSJ.ERRWARN);



ErrorCode=DSRunJob(JobHandle,DSJ.RUNNORMAL)

WaitError=DSWaitForJob(JobHandle)

J1stat = DSGetJobInfo(JobHandle,DSJ.JOBSTATUS)

call DSLogInfo("SendMailForWarnings status : ":J1stat, "DSSendMail")

If J1stat = 2 Then
Reply = DSSendMail(EmailDetails)

End
Post Reply