Class Message
Represents a Service ticket message.
Syntax
Examples
Message m;
m.load(2); // Loads message with id = 2
m.setValue("emailHeader", "Test");
m.setValue("body", "This is a test");
m.save();
Constructors
Message()
Initializes a new instance of the Message class.
Declaration
Message
Examples
Message m;
m.load(2); // Loads message with id = 2
m.setValue("emailHeader", "Test");
m.setValue("body", "This is a test");
m.save();
Methods
addHeader(String,String)
Adds a header to the message. The headers will be shown at the view request page, listed at the message.
Declaration
Void addHeader(String type, String value)
Parameters
Type | Name | Description |
---|---|---|
String | type | Type of header as a String, examples are To, Cc, SMS, Bcc |
String | value | The header to add as a String, common values are recipients of the message as a comma-separated String. |
Returns
Type | Description |
---|---|
Void |
Remarks
This method will only add a header if the message has been loaded or saved first. You do not need to call save() after this method.
Examples
Message m;
m.load(2); // Loads message with id = 2
m.setValue("emailHeader", "Test");
m.setValue("body", "This is a test");
m.save();
convertInlineImages()
Convert any inline images in the message from (cid: to normal http).
Declaration
Void convertInlineImages()
Returns
Type | Description |
---|---|
Void |
Examples
Message m;
m.load(2); // Loads message with id = 2
m.setValue("emailHeader", "Test");
m.setValue("body", "This is a test");
m.save();
getAttachments()
Returns an array of all the attachment IDs on the message.
Declaration
Integer[] getAttachments()
Returns
Type | Description |
---|---|
Integer[] | Array of attachment IDs. |
Examples
Message m;
m.load(2); // Loads message with id = 2
m.setValue("emailHeader", "Test");
m.setValue("body", "This is a test");
m.save();
getValue(String)
Returns the value a column.
Declaration
String getValue(String colName)
Parameters
Type | Name | Description |
---|---|---|
String | colName | Column name of the value. |
Returns
Type | Description |
---|---|
String | A string value of the column. |
Remarks
Possible columns:
- ticketId: Integer, The ticket this message is a child of.
- customerId: If the message was created by email or from the customer center, this field will point to that customer. -1 if the message was created by an user
- createdAt: Datetime when the message was created.
- createdBy: Integer, The ID of the user who posted the message. The value 1 (system user) for externally posted messages.
- type: String, The type of the message (plaintext/html).
- searchTitle: A copy of the title of the ticket, for search optimisation and simpler reporting.
- author: String, A string representing the author of the message. Could be a user's name, or a persons email address.
- slevel: String, The securitylevel of the message (1 is internal, 2 is external).
- messageId: String, The X-Message-Id header value from the email. Used for threading, i.e. connecting messages to existing tickets.
- timeSpent: Integer, The time spent (minutes) for this message.
- emailHeader: The email header is saved in this field as raw text
- debugInfo: The debug info for the message.
- important: True if this message is important.
- mailSorter: The name of the mail sorter used when the email was imported. Note: We must use name instead of id since the id's change every time one changes the mail sorter.
- inlineImages: True if message contains inline images.
- htmlBodyInlineConverted: True if the html_body has converted inline image links.
- inlineConverted: True if the html_body has converted inline image links.
- body: String, The textbody for the message.
- bodyHtml: String, The HTML body for the message (if any).
- badge: String, defines the initial source of message. See BadgeType.
- x_... : Extra fields
Examples
Message m;
m.load(2); // Loads message with id = 2
m.setValue("emailHeader", "Test");
m.setValue("body", "This is a test");
m.save();
load(Integer)
Loads the message with the given ID.
Declaration
load(Integer id)
Parameters
Type | Name | Description |
---|---|---|
Integer | id | ID of message. |
Returns
Type | Description |
---|---|
Bool | True if successful; otherwise, false. |
Examples
Message m;
m.load(2); // Loads message with id = 2
m.setValue("emailHeader", "Test");
m.setValue("body", "This is a test");
m.save();
save()
Saves a message and returns the database ID.
Declaration
Integer save()
Returns
Type | Description |
---|---|
Integer | The database Id. |
Remarks
You can optionally add logging.
Examples
Message m;
m.load(2); // Loads message with id = 2
m.setValue("emailHeader", "Test");
m.setValue("body", "This is a test");
m.save();
save(String)
Saves a message and returns the database ID.
Declaration
Integer save(String log)
Parameters
Type | Name | Description |
---|---|---|
String | log | Log entry to add to the ticket log that this message belongs to. |
Returns
Type | Description |
---|---|
Integer | The database Id. |
Remarks
Use save() if you don't want to add logging.
Examples
Message m;
m.load(2); // Loads message with id = 2
m.setValue("emailHeader", "Test");
m.setValue("body", "This is a test");
m.save();
save(String.Bool)
Saves a message and returns the database ID.
Declaration
Integer save(String log, Bool noNewInfo)
Parameters
Type | Name | Description |
---|---|---|
String | log | Log entry to add to the ticket log that this message belongs to. |
Bool | noNewInfo | Used in combination with log. Set it to false if your changes should turn the readStatus on ticket yellow (if the readStatus is green). |
Returns
Type | Description |
---|---|
Integer | The database Id. |
Remarks
Use save() if you don't want to add logging.
Examples
Message m;
m.load(2); // Loads message with id = 2
m.setValue("emailHeader", "Test");
m.setValue("body", "This is a test");
m.save();
saveInvolved(String)
Saves the email address of a single recipient of a message.
Declaration
Void saveInvolved(String emailAddress)
Parameters
Type | Name | Description |
---|---|---|
String | emailAddress | A single email address for 1 recipient. |
Returns
Type | Description |
---|---|
Void |
Remarks
Use save(Vector) to save a collection of addresses.
Examples
Message m;
m.load(2); // Loads message with id = 2
m.setValue("emailHeader", "Test");
m.setValue("body", "This is a test");
m.save();
saveInvolved(Vector)
Saves the email address of a single recipient of a message
Declaration
Void saveInvolved(Vector emailAddresses)
Parameters
Type | Name | Description |
---|---|---|
Vector | emailAddresses | A collection of email addresses for multiple recipients. |
Returns
Type | Description |
---|---|
Void |
Remarks
Use save(String) to save a single email address.
Examples
Message m;
m.load(2); // Loads message with id = 2
m.setValue("emailHeader", "Test");
m.setValue("body", "This is a test");
m.save();
send(Vector,Vector,Vector)
Sends an email version of the message to the main contacts on the parent ticket.
Declaration
Bool send(Vector to, Vector cc, Vector bcc)
Parameters
Type | Name | Description |
---|---|---|
Vector | to | The to-recipients in the email |
Vector | cc | The cc-recipients in the email |
Vector | bcc | The bcc-recipients in the email. |
Returns
Type | Description |
---|---|
Bool | True if everything is OK; otherwise, false. |
Remarks
Use one of the other variants if you want to merge with reply template or set subject and a heading for the body part.
Examples
Message m;
m.load(2); // Loads message with id = 2
m.setValue("emailHeader", "Test");
m.setValue("body", "This is a test");
m.save();
send(Vector,Vector,Vector,Integer)
Sends an email version of the message to the main contacts on the parent ticket. Merges with reply template in the settings of the submitted category ID.
Declaration
Bool send(Vector to, Vector cc, Vector bcc, Integer categoryId)
Parameters
Type | Name | Description |
---|---|---|
Vector | to | The to-recipients in the email |
Vector | cc | The cc-recipients in the email |
Vector | bcc | The bcc-recipients in the email |
Integer | categoryId | The ID of the category to check for reply template merge. Alternative to subject. |
Returns
Type | Description |
---|---|
Bool | True if everything is OK; otherwise, false. |
Examples
Message m;
m.load(2); // Loads message with id = 2
m.setValue("emailHeader", "Test");
m.setValue("body", "This is a test");
m.save();
send(Vector,Vector,Vector,String)
Sends an email version of the message to the main contacts on the parent ticket using the given subject
Declaration
Bool send(Vector to, Vector cc, Vector bcc, String subject)
Parameters
Type | Name | Description |
---|---|---|
Vector | to | The to-recipients in the email |
Vector | cc | The cc-recipients in the email |
Vector | bcc | The bcc-recipients in the email |
String | subject | The subject in the email. Alternative to categoryId. |
Returns
Type | Description |
---|---|
Bool | True if everything is OK; otherwise, false. |
Remarks
You can optionally provide a heading for the body part.
Examples
Message m;
m.load(2); // Loads message with id = 2
m.setValue("emailHeader", "Test");
m.setValue("body", "This is a test");
m.save();
send(Vector,Vector,Vector,String,String)
Sends an email version of the message to the main contacts on the parent ticket using the given subject, and a given heading for the body part.
Declaration
Bool send(Vector to, Vector cc, Vector bcc, String subject, String bodyHeading)
Parameters
Type | Name | Description |
---|---|---|
Vector | to | The to-recipients in the email |
Vector | cc | The cc-recipients in the email |
Vector | bcc | The bcc-recipients in the email |
String | subject | The subject in the email. Alternative to categoryId. |
String | bodyHeading | The body heading. Used with subject. |
Returns
Type | Description |
---|---|
Bool | True if everything is OK; otherwise, false. |
Remarks
The body heading may be empty for no heading, or null for default heading (same as not using this parameter).
Examples
Message m;
m.load(2); // Loads message with id = 2
m.setValue("emailHeader", "Test");
m.setValue("body", "This is a test");
m.save();
sendFacebook()
Posts message to Facebook
Declaration
Void sendFacebook()
Returns
Type | Description |
---|---|
Void |
Examples
Message m;
m.load(2); // Loads message with id = 2
m.setValue("emailHeader", "Test");
m.setValue("body", "This is a test");
m.save();
sendSms(Vector)
Sends an sms-version of the message to the numbers in the vector.
Declaration
Bool sendSms(Vector to)
Parameters
Type | Name | Description |
---|---|---|
Vector | to | The numbers to send the message to. |
Returns
Type | Description |
---|---|
Bool | True if successful; otherwise, false. |
Examples
Message m;
m.load(2); // Loads message with id = 2
m.setValue("emailHeader", "Test");
m.setValue("body", "This is a test");
m.save();
setAttachments(Vector)
Connects the attachments to the message.
Declaration
Void setAttachments(Vector ids)
Parameters
Type | Name | Description |
---|---|---|
Vector | ids | The IDs of the attachments. |
Returns
Type | Description |
---|---|
Void |
Remarks
You must do a message.save before message.setAttachments.
Examples
Message m;
m.load(2); // Loads message with id = 2
m.setValue("emailHeader", "Test");
m.setValue("body", "This is a test");
m.save();
setValue(String,String)
Sets the value of column colName to the given value
Declaration
Void setValue(String colName, String value)
Parameters
Type | Name | Description |
---|---|---|
String | colName | Column name of the value |
String | value | Value that should be stored in the column. |
Returns
Type | Description |
---|---|
Void |
Remarks
Possible columns:
- ticketId: Integer, The ticket this message is a child of.
- customerId: If the message was created by email or from the customer center, this field will point to that customer. -1 if the message was created by an user
- createdAt: Datetime when the message was created.
- createdBy: Integer, The ID of the user who posted the message. The value 1 (system user) for externally posted messages.
- type: String, The type of the message (plaintext/html).
- author: String, A string representing the author of the message. Could be a user's name, or a persons email address.
- slevel: String, The securitylevel of the message (1 is internal, 2 is external).
- messageId: String, The X-Message-Id header value from the email. Used for threading, i.e. connecting messages to existing tickets.
- timeSpent: Integer, The time spent (minutes) for this message.
- emailHeader: The email header is saved in this field as raw text
- debugInfo: The debug info for the message.
- important: True if this message is important.
- mailSorter: The name of the mail sorter used when the email was imported. Note: We must use name instead of id since the id's change every time one changes the mail sorter.
- inlineImages: True if message contains inline images.
- body: String, The textbody for the message.
- bodyHtml: String, The HTML body for the message (if any).
- badge: String, defines the initial source of message. See BadgeType.
- x_... : Extra fields
Examples
Message m;
m.load(2); // Loads message with id = 2
m.setValue("emailHeader", "Test");
m.setValue("body", "This is a test");
m.save();
toParser(Parser)
This function loads many fields of the message to the input parser.
Declaration
Void toParser(Parser parser)
Parameters
Type | Name | Description |
---|---|---|
Parser | parser | The parser that the message values is loaded into. |
Remarks
The fields will be loaded as message.value
- message.id, The ID of the message
- message.slevelInteger, The security level of the message. See TicketSecurityLevel.
- message.slevel, The security level of the message as a String, according to the active user's language.
- message.createdAt, The datetime when the message is created in format 12. jan 1998, kl. 11:23.
- message.createdAtRaw, The datetime when the message is created in format 1998-01-12 11:23:15
- message.author, The author of the message
- message.bodyHtml, The HTML body of the message
- message.messageCategory, The message category. See TicketMessageCategory.
- message.body, The body of the message, if this is a plaintext message, this text will be returned with activated links
- message.bodyPlain, The body of the message exactly as saved in database.
- message.header, The message header
- message.mailSorter, If this message is a recieved mail, the this is the name of the mail filter that took it.
- message.x_myextrafield, The value of the extrafield
Examples
Message m;
m.load(2); // Loads message with id = 2
m.setValue("emailHeader", "Test");
m.setValue("body", "This is a test");
m.save();