Go Back

User login

Frontpage Sponsor


Google search

For ERP LN feature pack upgrade, what method of install are you using?
Installation Wizard into existing VRC
Installation Wizard into new VRC
Manual into existing VRC
Manual into new VRC
Total votes: 43

Baanboard at LinkedIn

Reference Content

eMessage Connector examples
By patvdv at 26 Feb 2008 - 21:56

eMessage Connector examples


Tip: Maximize the help window for a good view of the examples.

How to use the eMessage Connector API to construct and send a message

In this example function cmf.send is used to send the message. The main difference with cmf.sendToPerson (see next section for an example) is that when using cmf.send only the message id is suplied as an argument, while cmf.sendToPerson needs both a message- and an addresslist id. This means cmf.send sends the message to the recipients in the message object, while cmf.sendToPerson sends the message to the recipients in the addresslist object.

 |* CMF Sample Code
 |* Script Type: 0

 Desc:   This code sample demonstrates the use of some of the Baan eMessage Connector commands
         described in the CMF 4GL Functional Design. It accepts a filename (which points to an RTF
         document), Baan eMessage Connector service name, recipient name and recipient address
          (SMTP only) as input arguments. It then uses the Baan eMessage Connector commands to
         construct a message then send it to the indicated recipients.
 Pre:    None.
 Post:   The file is sent to the appropriate Baan eMessage Connector service.
 In:     The four program arguments accepted are:
         sourcefile:     The name of the file (RTF format) to be sent.
         service:        This is the name of the service that will be used to send the message.
                 This must be name of a valid Baan eMessage Connector service
         name:   This is the (human readable) name of the recipient.
         address:        This the address where the file should be sent. This could be an email address,
                 a fax number, etc.
 Out:    None.

         string recipient.address(80)    |Recipient address
         string       |Human readable name of the recipient
         string sourcefile(256)          |Filename of the source file

 function main()
         domain ttcmf.prov service       |Baan eMessage Connector service for transporting messages
         long stat       |Variable to hold return values
         long mid        |CMF message id

         |Switch to company 0

         |Get program arguments
         sourcefile = strip$(argv$(1))
         service = strip$(argv$(2)) = strip$(argv$(3))
         recipient.address = strip$(argv$(4))

         |Build message XML header
         mid = create.xml.header()

         |Send message
         if mid <>0 then
                 stat = cmf.startService(service,2)
                 if stat<>0 then
                         message("Message could not be sent (Baan eMessage Connector service did not start)")
                 stat = cmf.send(mid,service)
                 if stat<>0 then
                         message("Message could not be sent (Baan eMessage Connector service refused message)")
                 stat = cmf.stopService(service,2)

 function long create.xml.header()
         long    message.ID
         long    from.ID
         long    to.ID
         long    attachment.ID
         long    ret

         message.ID = cmf.create()

         ret = cmf.setClass(message.ID, "CMF.NOTE")
         ret = cmf.setSubject(message.ID, "Sample CMF Message")

         |Set FROM recipient
         from.ID = cmf.createRecipient(message.ID, ttcmf.role.from)
         ret = cmf.setRecipientName(from.ID, "John Doe")
         ret = cmf.setRecipientAddress(from.ID,"")
         ret = cmf.setRecipientType(from.ID, "SMTP")
         |In reality of course the from address could be filled from the
         |Address book.

         |Set TO recipient
         to.ID = cmf.createRecipient(message.ID,
         ret = cmf.setRecipientName(to.ID,
         ret = cmf.setRecipientAddress(to.ID, recipient.address)
         ret = cmf.setRecipientType(to.ID, "SMTP")
         ret = cmf.setRecipientResponsibility(to.ID, "TRUE")

         |Set attachment
         attachment.ID = cmf.createAttachment(message.ID)
         ret = cmf.setAttachmentBody(attachment.ID, "TRUE")
         ret = cmf.setAttachmentMIME(attachment.ID, "application/rtf")
         ret = cmf.setAttachmentFileName(attachment.ID,sourcefile,
                                                 "Sample Attachment")


How to use function cmf.sendToPerson

Use cmf.sendToPerson if the same message has to be send to multiple recipients and when using the Message Dialog to construct message- and addresslist objects. As arguments a message-id of a message object and an addresslist-id of an addresslist object (among others) have to be supplied. Cmf.sendToPerson delivers the message to all recipients on the addresslist. Message- and addresslist objects can be constructed in two ways:

  • With user interface: use the Message Dialog. Using this session the user can determine some message characteristics and construct an addresslist. After exiting the Message Dialog, the id’s of the message- and addresslist objects are available in the variables cmf.MessageObject and cmf.AddressList (defined in global include file bic_global).
  • Without user interface: use the eMessage Connector API to build a message- and addresslist object. But watch out: using cmf.sendToPerson the message will solely be delivered to recipients in the addresslist object. Any recipients in the message object will NOT be reached.
 |* Example of usage of cmf.sendToPerson
 |* Script Type: 0

 table   tttcmf200       |Address Book
 table   tttaad200       |User Data

 #include "ittadv0001"

 function main()

 function sendMessage()
         long    ret     |return value of various functions
         long    show.progress   |if true, progress indicator will be
                         |shown to user. If false, no indicator
                         |is shown
         string  message.str(250)        |success or error message set by
         string  addresstype(30) |string representation of message type
                         |used to send message
         string  role.str(6)     |string representaton of role of
         string  address(80) mb  |address of recipient
         domain  ttaad.user user |key of table ttaad200 User Data
         domain  ttcmf.catg catg |category of a recipient in Address Book
                         |(for example: BAAN USER, EMPLOYEE etc.)
         domain  ttcmf.catg akey |key of recipient: must uniquely
                         |identify entry in Address Book within
                         |a category
         domain  ttcmf.role role |role of a recipient (from/to etc.)

         show.progress   = 0
         message.str     = ""
         addresstype     = ""
         catg    = ""
         akey    = ""
         role.str        = ""
         user    = ""
         role    = empty

         |create message- and addresslist objects
         cmf.MessageObject = cmf.create()
         cmf.AddressList = cmf.createAddressList()

       |fill addresslist with data from Address Book: first select baan users
       |from User Data table (ttaad200), then select for each user their
       |address data from the Address Book (ttcmf200). Then add user as entry
       |to the addressslist object
       |NOTE: in this example only one user is selected from the User Data
       |table. Also, role of recipient is always "to".
       |NOTE: in this example the default addresstype is used to resolve the
       role =
       user = "skalma"
         select ttaad200.user
         from ttaad200
         where ttaad200._index1 = {:user}
         as set with 1 rows
                 catg = "BAAN USER"
                 akey = toupper$(strip$(ttaad200.user))

                 select ttcmf200.*
                 from ttcmf200
                 where ttcmf200._index1 = {:catg, :akey}
                 as set with 1 rows
                         ret =      role,

                         ret =,
                         ret = cmf.resolveAddress(       catg,

                         ret = cmf.addAddressEntry(      cmf.AddressList,
                                 role.str,       |role
                       ,  |name
                                 ttcmf200.mail,  |address
                                 addresstype)    |message type

         |set identification attributes
         ret = cmf.setClass(cmf.MessageObject, "CMF.NOTE")
         ret = cmf.setSubject(cmf.MessageObject, "Message to" & strip$(

         |set delivery attributes
         ret = cmf.setPriority(cmf.MessageObject, ttcmf.prio.high)
         ret = cmf.setSensitivity(cmf.MessageObject, ttcmf.sens.secret)
         ret = cmf.setNotification(cmf.MessageObject, ttcmf.noti.nondelivery)

         |set cmf.ShowMessage: indicates whether cmf.sendToPerson must try to start up a user
         |interface based service (for example Outlook) to send this message: 1 means yes, 0
         |means no.
         cmf.ShowMessage = 1

         |set show.progress to false: no indicator shown to user
         show.progress = false

         |send message
         ret = cmf.sendToPerson( cmf.MessageObject,

         |show message.str
         if not isspace(message.str) then
                 if ret < 0 then
                         mess("ttcmf01303", 1, message.str)
                         |* %s (warning)
                         mess("ttstpsplclose2", 1, message.str)
                         |* %s (information)

         |stop all started services that were started by cmf.sendToPerson

         |destroy objects
         ret = cmf.destroy(cmf.MessageObject)
         ret = cmf.destroy(cmf.AddressList)

How to use the message dialog

Here one report is created and send to multiple recipients using cmf.sendToPerson. The message dialog is used to construct the message and addresslist objects.

 |* Send Same Report to Multiple Recipients
 |* Script Type: 0
 table   tttadv002       | Baan Tools Parameters
 table   tttaad100       | Companies
 table   tttaad110       | Languages
 table   tttaad120       | Packages
 table   tttaad200       | User Data
 table   tttadv111       | Package VRC's
 table   tttadv360       | Menus
 table   tttams200       | Role Data
 table   tttaad121       | Package Combinations Packages

 #include "ittadv0001"   |compnr. and last-used functions

 #define OK              0
 #define NOT.FOUND       1
 #define EXPIRED         2

 function main()
         |form variables
         extern  domain  ttaad.user      user.f  fixed   |on form: from Baan user
         extern  domain  ttaad.user      user.t  fixed   |on form: to Baan user
         extern  domain  ttdsca  pacc.desc       |package combination
         extern  domain  ttdsca  comp.desc       |company description
         extern  domain  ttdsca  lang.desc       |language description
         extern  domain  ttdesc60        stmn.desc
         extern  domain  ttdsca  role.desc       |role description
         extern  domain  ttams.crol      role    |role of user

         |report variable
         extern  domain  ttst30          |used to determine which parts of report
                                         |will be written to the report file


         long    ret     |return vales of various functions
         long    brp_id  |id of report
         domain  ttdesc200 message.str   |contains error message. set by

         ret     = 0
         brp_id  = 0
         message.str     = ""

         |open spooler and activate report without user interface
         spool.fileout = "${BSE}/tmp/user_data_report"
         brp_id ="rttams140111000", "ASCIF", 0)
         on case brp_id
         case 0:
                 |Error in opening report
         case -1:
                 |Printing cancelled

         |user.f and user.t normally set on form
         user.f  = "gmurre"
         user.t  = "gmurre"

         | data in range is send to opened report
         select ttaad200.user
         from ttaad200
         where ttaad200.user inrange :user.f and :user.t
                 | send User
        = "user"

                 | send system-data
        = "sysd.header"
        ttaad200.user, brp_id)
        = "sysd.footer"

                 | send defaults
        = "def.header"
        ttaad200.user, brp_id)
        = "def.footer"

                 | send authorizations
        = "auth.header"
        ttaad200.user, brp_id)
        = "auth.footer"

                 | send empty line
        = "empty"
         | stops report writer for the report

         |activate Message Dialog with only Message Formtab: user can set some
         |message characteristics and construct a recipient list
         ret = cmf.messageDialog(2, CMF.MESSAGE)
         on case ret
         case -1:
                 |error launcing Message Dialog
         case -2:
                 |invalid argument values

         |send message: after Message Dialog is closed, message object- and
         |addresslist object id's are available in variables cmf.MessageObject
         |and cmf.AddressList. Also, the user can determine if a user interface
         |based service has to be started by checking the checkbox 'Show Message
         |before Sending (if possible)'. If checked, cmf.ShowMessage will be 1,
         |else 0.
         ret = cmf.sendToPerson( cmf.MessageObject, cmf.AddressList,
                 cmf.ShowMessage, true, message.str, true,

         |display message
         if not isspace(message.str) then
                 if ret < 0 then
                         |error message
                         mess("ttcmf01303", 1, message.str)
                         |* %s (warning)
                         |succes message
                         mess("ttstpsplclose2", 1, message.str)
                         |* %s (information)

         |stop all the services started up by cmf.sendToPerson

         |delete xml-objects
         if cmf.MessageObject <> 0 then
                 ret = xml.deleteNode(cmf.MessageObject)
         if cmf.AddressList <> 0 then
                 ret = xml.deleteNode(cmf.AddressList)

Related topics

No votes yet

All times are GMT +2. The time now is 07:19.

©2001-2017 - -