IES PRINT WRITER: PDF MAIL RUNS - SHELL PROGRAM

Purpose

The purpose of this Document is to provide the Developer with a basic shell program that includes the steps for setting up a pdf mail run, and which may be expanded by inclusion of the necessary logic to fit your requirements.

Introduction

To set up a "PDF mail run" in which various documents are created and dispatched by e-mail to multiple addresses, you will write a program which is then placed in the Menu Process Library, from where it may be offered on a standard User Menu for execution.

The program will perform all required steps, and in this document, we show such a shell program. The shell program is incomplete, i.e. you have to expand the logic to include what you wish to achieve, but it is quite easy to do so when using the shell or 'template' program as a basis. This program is called 'do.pdf.mail.run' and you will find the source in an IES Business Datamart in the file "cbp". From here, you can copy it to a new name in "client.bp", modify and expand the program, and then place it in the Menu Process Library for use.

The Shell Program

subroutine do.pdf.mail.run * equate am to char(254), vm to char(253), svm to char(252) * * * This is a shell or template program only, and is intended * as a guide to the Developer to develop a 'pdf mail run' * program that employs PrintWriter and DocWriter to create * documents (statements or other reports), which are then * converted to pdf and dispatched seamlessly by e-mail. * * * For this program to work properly, it will be a requirement * that PDFCreator is present as a printer on the Workstation * where this is executed, and the mail client (e.g. Outlook, Express * or other) should be set with permission to send e-mail on behalf * of an Application without asking permission each time ... * *** *** * declare the files that will be written or read file docwritespre file custfile file failfile file datacap *** *** * determine the UserCode and Port, which will be the key * to use on file "docwritespre" param = '26' ; port = '' ; call s.peek(param,port) param = '6' ; usercode = '' ; call s.peek(param,usercode) *** *** * if there is a need to offer a screen for the user to capture * some required values, we may call the screen 1st - in our example * we are using a fictional screen called 'screen1' which is also * present in the Menu Process Library as 'screen1' ref = 'screen1' ermes = '' call s.logi(ref,ermess) * and maybe we read back the result of what is captured; in this * example, we suggest there is a 'statement header' that we need read datacap from port then stateheader = datacap(stateheader) end else * the user never saved the screen go mainexit end *** *** * it may be necessary to offer the User a Data Selector to select * only those records intended for use in this run; for example * we could say that we select records from 'custfile', and there * is a data selector also that is called 'custfile' dselector = 'custfile' call makelist.t(dselector) command = 'get-list portlist*':port execute command if system(11) else * no records selected go mainexit end select to klist *** *** * now we can use the selected records and loop though them to * produce and mail the document in each case nexrec: * readnext custkey from klist then gosub perform.doc go nexrec end *** *** * transfer to program exit go mainexit *** *** * beginning of subroutine section perform.doc: * * for each document we perform, we will call a printwriter process, * which is already present in the menu process library * in each case, printwriter will be calling the designated docwriter * process, which may already include a prerun program to format * some data and record it in "docwritespre" to be accessed by docwriter * to produce the resulting report, OR we may call a program from here, * for example a program that formats the necessary customer data into * docwritespre, and when docwriter is called, the data will already * be there * before we call the printwriter for the current customer, we need * to pass instructions into 'docwritespre' to provide the current * e-mail address and other parameters for the mail to be dispatched * and after calling printwriter we may want to check the result, i.e. * if there was an error or not * we call another program we have already written (not supplied here) * and which will format some cust data into docwritespre using key= * usercode call myformatprog(custkey) * now we read the customer record to determine the e-mail address read custfile from custkey then email = custfile(email) end else * how can the rec not be there? go slip.perform.doc end * the docwriter object will use data on the rec in 'docwritespre' where * the key=usercode (and this data was already formatted when we called * 'myformatprog', and now we will pass the necessary instructions for * printwriter, also into 'docwritespre', but using key=port. x = '' x<1> = email ; * email address x<2> = 'Your Statement: ':stateheader ; * mail title * x<3> may be used for message text, and may be multi-valued, i.e. * multiple lines of text - we are not doing it here x<4> = 'Statement' ; * this is the name that will be assigned to * to the attached pdf, it needs to be a valid * filename, and the system will put the '.pdf' x<8> = 'Mailing Statement for Customer ':custkey ; * message to be * displayed on screen while processing docwritespre = x write docwritespre on port * at this stage we can call printwriter, which process we have * predefined in the Menu Process Library as 'cstate-pdf' ref = 'cstate-pdf' ermes = '' call s.logi(ref,ermes) * by now, the mail has gone out or has failed * read docwritepre from port then x = docwritespre * if there is a value on field 5, it was successful senddate = x<5> if senddate = '' then * failed, the error will be on field 7 failmes = x<7> * we can record the failure on some error file and provide * a report later if we want - code not shown end else sendtime = field<6> * we can record the success perhaps on the customer rec * for future enquiry - code not shown end end slip.perform.doc: * return *** *** * end of subroutine section * mainexit: * * return

© Infolab, 2005.