NAV 2015

“Check NAS” Process execution and Send Mail (Batch control)


“Check NAS” Process execution & Send Mail (Batch control)

How System Works

> System every “X minutes” check Status of Scheduled Processes and send a mail with Status (batch control)

Scheduling

> You can schedule this codeunit in some or in another Process Category Queue of your NAS; you can use also another separate NAS Server if you need parallelasynchronous check.

 

Codeunit “Check NAS” C/AL Code

Documentation

RS, NAS01, 20150710, “Check NAS” Codeunit

*** Function “CreaFileErrori

*** Function “ErrorSendMail

*** Function “JobStatus

OnRun()

//RS, NAS01, .sn

//Call Create Errors File

CreaFileErrori;

//RS, NAS01, .en

JobStatus()

//RS, NAS01, .sn

// Check “Job Log Entry” Process Status & Execution Time

IF recJobQEntry.FINDSET THEN

REPEAT //controllo se è in esecuzione da troppo tempo (check for LONG running time execution)

recJobQEntry.”Send error email” := FALSE;

IF (recJobQEntry.Status = recJobQEntry.Status::”In Process”) THEN

BEGIN

recJobQLogEntry.SETRANGE(“Object Type to Run”,recJobQEntry.”Object Type to Run”);

recJobQLogEntry.SETRANGE(“Object ID to Run”,recJobQEntry.”Object ID to Run”);

IF recJobQEntry.”Duration Process Max” > 0 THEN

IF recJobQLogEntry.FINDLAST THEN

IF CURRENTDATETIME – recJobQLogEntry.”Start Date/Time” > recJobQEntry.”Duration Process Max” THEN

recJobQEntry.”Send error email” := TRUE;

END

ELSE //se è in errore , IF process Is in “Error” State

IF (recJobQEntry.Status = recJobQEntry.Status::Error) THEN

recJobQEntry.”Send error email” := TRUE;

recJobQEntry.MODIFY;

UNTIL recJobQEntry.NEXT = 0;

//RS, NAS01, .en

ErrorSendEmail(txtFile01 : Text[100])

//RS, NAS01, .sn

//————— Build & Send Mail ———————-//

recSMTP.GET;

cuSendEmail.CreateMessage(recSMTP.”User ID”,

recSMTP.”Sender Address”,

recSMTP.”Receiver Address Log Interface”,

‘Errori Job Schedulate’,’In allegato i job in errore’,

FALSE);

//Add attachment

cuSendEmail.AddAttachment(txtFile01);

//Send attachment

cuSendEmail.Send;

//RS, NAS01, .en

CreaFileErrori()

//RS, NAS01 .sn

// Registrazione Errori NAS, Wrinting NAS Errors in Outpout File

GLOBALLANGUAGE(1040);

CLEAR(OutFile);

OutFile.TEXTMODE := TRUE;

OutFile.WRITEMODE := TRUE;

recSMTP.GET;

txtFileName_00 := recSMTP.”Error Folder Log” + recSMTP.”Error File Log”

+ DELCHR((FORMAT(TODAY,0,'<Year4><Month,2><Day,2>’) +’_’+ FORMAT(TIME)), ‘=’,’/ : .’) + ‘.csv’;

IF OutFile.OPEN(txtFileName_00) THEN

BEGIN

OutFile.CLOSE;

EXIT;

END;

OutFile.CREATE(txtFileName_00);

txtFineRiga:='<CRLF>’;

cr:=13;

lf:=10;

recJobQEntry.SETRANGE(“Send error email”,TRUE);

IF  recJobQEntry.FINDSET THEN

BEGIN

REPEAT

txtOutText:= ‘TIPO;’ + ‘NR JOB;’ + ‘JOB;’;

OutFile.WRITE(txtOutText); //scrivo riga

txtOutText:=FORMAT(FORMAT(recJobQEntry.”Object Type to Run”)+ ‘;’ +

FORMAT(recJobQEntry.”Object ID to Run”)+ ‘;’ +

recJobQEntry.Description, -250);

OutFile.WRITE(txtOutText); //scrivo riga , Write Line

txtOutText := ‘MESSAGGIO;’;

OutFile.WRITE(txtOutText); //scrivo riga, Write Line

OutFile.WRITE(FORMAT(recJobQEntry.”Error Message”,-250)); //scrivo riga

OutFile.WRITE(FORMAT(recJobQEntry.”Error Message 2″,-250)); //scrivo riga

OutFile.WRITE(FORMAT(recJobQEntry.”Error Message 3″,-250)); //scrivo riga

OutFile.WRITE(FORMAT(recJobQEntry.”Error Message 4″,-250)); //scrivo riga

CLEAR(txtOutText);

UNTIL  recJobQEntry.NEXT = 0;

END

ELSE

BEGIN

txtOutText:=’Nessun Errore’;

OutFile.WRITE(txtOutText);

END;

OutFile.CLOSE;  //chiudofile

// INVIO EMAIL CON ALLEGATI, SEND MAIL WITH ATTACHMENTS

ErrorSendEmail(txtFileName_00);

//RS, NAS01 .en

CODEUNIT SCHEDULING SAMPLE

Schedule Codeunit on NAS (example every 60 minutes)

nav 1

“SMTP MAIL Setup” Table with New Fields

smtp

New Fields to insert:

  • Field: File Attachment
  • Field: Patch Attachment
  • Field: Receiver Address
  • Field: VBScript Folder
  • Field: Receiver Address Log Interface
  • Field: Error Folder Log
  • Field: Receiver Warning
  • Field: Error File Log
  • Field: Sender Name
  • Field: Sender Address

RUN TABLE AND ENTER DATA IN NEW FIELDS (add fields on your Standard NAV Page)

nas 4

File Directory

  • Files are stored in “\NavisionShared\Log” > you can change by Setup

nas 6

Error File Sample NavJob20150706_170544”  FILE DETAILS

nas 7

Annunci

Categorie:NAV 2015, NAV Nas

Con tag:,

Rispondi

Inserisci i tuoi dati qui sotto o clicca su un'icona per effettuare l'accesso:

Logo WordPress.com

Stai commentando usando il tuo account WordPress.com. Chiudi sessione / Modifica )

Foto Twitter

Stai commentando usando il tuo account Twitter. Chiudi sessione / Modifica )

Foto di Facebook

Stai commentando usando il tuo account Facebook. Chiudi sessione / Modifica )

Google+ photo

Stai commentando usando il tuo account Google+. Chiudi sessione / Modifica )

Connessione a %s...