> ## Documentation Index
> Fetch the complete documentation index at: https://docs.superoffice.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Create and update messages

> How to create and update request messages in CRMScript.

## Void setValue(String colName, String value)

Sets a named field to the given value. Look up names in the reference section down below, or check out the [class reference][1].

<Note>
  Both parameters are strings! Remember to use quotes even for IDs.

  You must call `save()` after setting all applicable values to actually create or update the message.
</Note>

```crmscript! theme={null}
Message m;
m.setValue("emailHeader", "Test");
m.setValue("body", "This is a test");
print(m.save().toString());
```

### Frequently used values

| Parameter   | Db field      | Description                                                 |
| :---------- | :------------ | :---------------------------------------------------------- |
| ticketId    | ticket\_id    | The ticket this message is a child of                       |
| type        | type          | Plaintext or HTML                                           |
| author      | author        | A user's name, or a persons email address                   |
| createdBy   | created\_by   | The ID of the user who posted the message (1: system)       |
| slevel      | slevel        | The security level of the ticket (1: internal, 2: external) |
| message\_id | message\_id   | The X-Message-Id email header. Used for threading           |
| body        | body          | The text body for the message                               |
| bodyHtml    | html\_body    | The html body for the message (if any)                      |
| emailHeader | email\_header | Raw text header                                             |

For a complete list of fields, see the [database reference][3].

## Void setAttachments(Vector ids)

Connects 1 or more attachments to the message. Attachments are identified by their ID.

<Note>
  You must call `save()` before calling `setAttachments()`!
</Note>

```crmscript theme={null}
Message m;
m.setValue("ticketId","4");
m.save();
Vector v;
v.parseString("1,4,7",",");
m.setAttachments(v);
m.save();
```

## Void addHeader(String type, String value)

Adds a display header to the message. Not to be confused with email header!

Display headers are shown at the **View request** page when listing messages.

Commonly used types are *To*, *Cc*, *Bcc*, and *SMS*. The corresponding value would then be the recipients as a comma-separated list.

```crmscript theme={null}
Message m;
m.load(1);
m.addHeader("To","post@company.com");
m.save();
```

## Integer save()

Saves a new or updated message and returns its ID.

```crmscript theme={null}
Message m;
m.setValue("type","html");
m.save();
```

## Integer save(String log)

A variant of `save()` that also adds a message to the ticket log.

```crmscript theme={null}
Message m;
m.setValue("type","html");
m.save("This is a duplicate.");
```

## Integer save(String log, Bool noNewInfo)

A  variant of `save()` with a setting for controlling processing:

* `noNewInfo`: if **false**, set the read status on ticket to yellow (if currently green)

```crmscript theme={null}
Message m;
m.setValue("createdBy","1");
m.save("Need to follow up",true);
```

## Using reply templates

You can save time by using a reply template as your basis.

### Void toParser(Parser parser)

Passes relevant data from the message to the parser.

* message.id
* message.slevel, message.slevelInteger (as text in the active user's language and as number)
* message.createdAt, message.createdAtRaw (formats *DD. MMM YYYY, kl. hh:mm* and *YYYY-MM-DD hh:mm:ss*)
* message.author
* message.header
* message.body, message.bodyPlain, message.bodyHtml
* message.messageCategory (Message: 0, Bounce: 1, OutboxFailed: 2)
* message.mailSorter (mail filter applied to incoming message)
* message.x\_myextrafield (extrafield value)

```crmscript! theme={null}
Message m;
m.setValue("body", "Thank you, mr. Data!");
m.setValue("type", "html");

Parser p;
m.toParser(p);
printLine("Body passed to parser: " + p.getVariable("message.body",0));

ReplyTemplate rt;
rt.load(19);
String htmlBody = rt.getHtmlBody(2);

m.setValue("bodyHtml" , p.parseString(htmlBody));

printLine("\nHTML body of message after parsing:\n\n" + m.getValue("bodyHtml"));
```

Read more about [the parser][5] and [reply templates][4].

### Void convertInlineImages()

Converts any inline images from content ID (cid:) to standard HTTP.

```crmscript theme={null}
Message m;
m.convertInlineImages();
m.save();
```

[1]: /en/automation/crmscript/reference/CRMScript.Native.Message#setvaluestringstring

[3]: ../../../../database/tables/ej-message

[4]: ./reply-templates

[5]: ../../parser


## Related topics

- [Create and update requests](/en/automation/crmscript/howto/request/create.md)
- [Create and update customers](/en/automation/crmscript/howto/contact/create-user.md)
- [Create Message](/en/api/reference/restful/agent/messaging_agent/create-message.md)
- [Create Default Shipment Message Entity](/en/api/reference/restful/agent/marketing_agent/create-default-shipment-message-entity.md)
- [Create Default Shipment Message Block Entity](/en/api/reference/restful/agent/marketing_agent/create-default-shipment-message-block-entity.md)
- [Create and update companies](/en/automation/crmscript/howto/company/create-company.md)
