# IssueComment

Represents a comment that is added to an issue.

Extends [BaseComment](v1-BaseComment.html).

## Properties

| Name | Type | Description |
| --- | --- | --- |
| attachments |  [Set](v1-Set.html).<[IssueAttachment](v1-IssueAttachment.html)>  | Read-only.  The set of attachments that are attached to the comment.             Available since 2018.1.40030    |
| author |  [User](v1-User.html)  | Read-only.  The user who created the comment.   |
| becomesRemoved |  Boolean  | Read-only.  When `true`, the entity is removed in the current transaction. Otherwise, `false`. This property can become `true` only in on-change rules when the rule is triggered on the removal of an issue or an article. In the rule code, the `runOn` rule property must contain the `removal` parameter set to `true`.             Available since 2017.4.37915      ```JAVASCRIPT runOn: {removal: true} ```    |
| created |  Number  | Read-only.  Time the comment was created.   |
| deleted |  Boolean  | Read-only.  `true` in case the comment is displayed as removed.             Available since 2020.6.4500    |
| extensionProperties |  Object  |  The object containing extension properties for this entity and their values. Extension properties are custom properties that might be added to core YouTrack entities by an app. For details about extension properties, see [Extension Properties](apps-extension-properties.html).             Available since 2024.3      ```JAVASCRIPT const entities = require('@jetbrains/youtrack-scripting-api/entities');  exports.rule = entities.Issue.action({     command: 'test',     action: function (ctx) {         const printValues = () => {             return 'stringProp:' + ctx.issue.extensionProperties.stringProp + ';'                 + 'integerProp:' + ctx.issue.extensionProperties.integerProp + ';'                 + 'booleanProp:' + ctx.issue.extensionProperties.booleanProp + ';'                 + 'issueProp:' + ctx.issue.extensionProperties.issueProp?.id + ';'                 + 'issuesProp:' + ctx.issue.extensionProperties.issuesProp?.first()?.id + ';'         }         ctx.issue.addComment(printValues());     } }); ```    |
| isNew |  Boolean  | Read-only.  When `true`, the entity is created in the current transaction. Otherwise, `false`.             Available since 2018.2.42351    |
| isPinned |  Boolean  |  When `true`, the comment is pinned in the issue. Otherwise, `false`.             Available since 2024.1    |
| issue |  [Issue](v1-Issue.html)  | Read-only.  The issue the comment belongs to.   |
| permittedGroup |  [UserGroup](v1-UserGroup.html)  |  A group whose members are allowed to access the comment.   |
| permittedGroups |  [Set](v1-Set.html).<[UserGroup](v1-UserGroup.html)>  |  Groups whose members are allowed to access the comment.   |
| permittedUsers |  [Set](v1-Set.html).<[User](v1-User.html)>  |  Users who are allowed to access the comment.   |
| text |  String  |  The text of the comment.   |
| updated |  Number  | Read-only.  Time the comment was last updated.   |
| updatedBy |  [User](v1-User.html)  | Read-only.  The user who last updated the comment.   |
| url |  String  | Read-only.  The absolute URL (permalink) that points to the comment.             ```JAVASCRIPT user.notify('Somebody has written something', 'Have a look: ' + comment.url); ```    |

## Methods

### action

```JAVASCRIPT
static action(ruleProperties)
```

Creates a declaration of a rule that a user can apply to an issue comment using a menu option. The object that is returned by this method is normally exported to the `rule` property, otherwise it is not treated as a rule.

Parameters
: | Name | Type | Description |
: | --- | --- | --- |
: | ruleProperties |  Object  |  A JSON object that defines the properties for the rule.                     |

Properties of ruleProperties
: | Name | Type | Description |
: | --- | --- | --- |
: | title |  string  |  The human-readable name of the rule. Displayed in the administrative UI in YouTrack.                     |
: | userInput |  Object  |  An object that defines the properties for information that will be requested from the user who triggers the action rule.                     |
: | userInput.type |  string, Object  |    The data type for the value that is requested from the user.     The supported types are [entities.Field.dateTimeType](v1-Field.html), [entities.Field.dateType](v1-Field.html), [entities.Field.integerType](v1-Field.html), [entities.Field.floatType](v1-Field.html), [entities.Field.periodType](v1-Field.html), [entities.Field.stringType](v1-Field.html), [entities.Build](v1-Build.html), [entities.EnumField](v1-EnumField.html), [entities.Issue](v1-Issue.html), [entities.IssueTag](v1-IssueTag.html), [entities.OwnedField](v1-OwnedField.html), [entities.Project](v1-Project.html), [entities.ProjectVersion](v1-ProjectVersion.html), [entities.UserGroup](v1-UserGroup.html), and [entities.User](v1-User.html).    |
: | userInput.description |  string  |  The label for the control that is used to collect additional information from the user.                     |
: | guard |  [IssueComment]()~guardFunction  |  A function that is invoked to determine whether the action is applicable to an issue comment.                     |
: | action |  [IssueComment]()~actionFunction  |  The function that is invoked when a user triggers this action.                     |
: | requirements |  [Requirements](v1-Requirements.html)  |  The set of entities that must be present for the script to work as expected.                     |

Return Value
: | Type | Description |
: | --- | --- |
: |  Object  |  The object representation of the rule.                 |

Example
: ```JAVASCRIPT
: var entities = require('@jetbrains/youtrack-scripting-api/entities');
: exports.rule = entities.IssueComment.action({
: title: 'Log comment text if comment has attachments',
: guard: function(ctx) {
: return !ctx.issueComment.attachments.isEmpty();
: },
: action: function(ctx) {
: console.log(ctx.issueComment.text);
: }
: });
: ```

### findByExtensionProperties

```JAVASCRIPT
static findByExtensionProperties(extensionPropertiesQuery)
```

Searches for IssueComment entities with extension properties that match the specified query.

Available since 2024.3.43260

Parameters
: | Name | Type | Description |
: | --- | --- | --- |
: | extensionPropertiesQuery |  Object  |  The extension properties query, defined as a set of key-value pairs representing properties and their corresponding values.                     |

Return Value
: | Type | Description |
: | --- | --- |
: |  [Set](v1-Set.html).<[IssueComment]()>  |  The set of IssueComment entities that contain the specified extension properties.                 |

Example
: ```JAVASCRIPT
: {
: property1: "value1",
: property2: "value2"
: }
: ```

### addAttachment

```JAVASCRIPT
addAttachment(content, name, charset, mimeType)
```

Attaches a file to the issue comment. Makes `issue.attachments.isChanged` return `true` for the current transaction.

Available since 2020.6.3400

Parameters
: | Name | Type | Description |
: | --- | --- | --- |
: | content |  InputStream, String, [JsonForIssueCommentAddAttachment](v1-JsonForIssueCommentAddAttachment.html)  |  The content of the file in binary or base64 form. Alternatively, pass a JSON specified by [JsonForIssueCommentAddAttachment](v1-JsonForIssueCommentAddAttachment.html)                     |
: | name |  String  |  The name of the file.                     |
: | charset |  String  |  The charset of the file. Only applicable to text files.                     |
: | mimeType |  String  |  The MIME type of the file.                     |

Return Value
: | Type | Description |
: | --- | --- |
: |  [IssueAttachment](v1-IssueAttachment.html)  |  The attachment that is added to the issue comment.                 |

### becomes

```JAVASCRIPT
becomes(fieldName, expected)
```

Checks whether a field is set to an expected value in the current transaction.

Parameters
: | Name | Type | Description |
: | --- | --- | --- |
: | fieldName |  string  |  The name of the field to check.                     |
: | expected |  string  |  The expected value.                     |

Return Value
: | Type | Description |
: | --- | --- |
: |  boolean  |  If the field is set to the expected value, returns `true`.                 |

### canBeReadBy

```JAVASCRIPT
canBeReadBy(fieldName, user)
```

Checks whether a user has permission to read the field.

Parameters
: | Name | Type | Description |
: | --- | --- | --- |
: | fieldName |  string  |  The name of the field.                     |
: | user |  [User](v1-User.html)  |  The user for whom the permission to read the field is checked.                     |

Return Value
: | Type | Description |
: | --- | --- |
: |  boolean  |  If the user can read the field, returns `true`.                 |

### canBeWrittenBy

```JAVASCRIPT
canBeWrittenBy(fieldName, user)
```

Checks whether a user has permission to update the field.

Parameters
: | Name | Type | Description |
: | --- | --- | --- |
: | fieldName |  string  |  The name of the field.                     |
: | user |  [User](v1-User.html)  |  The user for whom the permission to update the field is checked.                     |

Return Value
: | Type | Description |
: | --- | --- |
: |  boolean  |  If the user can update the field, returns `true`.                 |

### delete

```JAVASCRIPT
delete()
```

Logically deletes the comment. This means that the comment is marked as deleted, but remains in the database. Users with sufficient permissions can restore the comment or delete the comment permanently from the user interface. The option to delete comments permanently has not been implemented in this API.

Available since 2018.1.38923

### is

```JAVASCRIPT
is(fieldName, expected)
```

Checks whether a field is equal to an expected value.

Available since 2019.2.55603

Parameters
: | Name | Type | Description |
: | --- | --- | --- |
: | fieldName |  string  |  The name of the field to check.                     |
: | expected |  string  |  The expected value.                     |

Return Value
: | Type | Description |
: | --- | --- |
: |  boolean  |  If the field is equal to the expected value, returns `true`.                 |

### isChanged

```JAVASCRIPT
isChanged(fieldName)
```

Checks whether the value of a field is changed in the current transaction.

Parameters
: | Name | Type | Description |
: | --- | --- | --- |
: | fieldName |  string  |  The name of the field to check.                     |

Return Value
: | Type | Description |
: | --- | --- |
: |  boolean  |  If the value of the field is changed in the current transaction, returns `true`.                 |

### isVisibleTo

```JAVASCRIPT
isVisibleTo(user)
```

Checks whether the specified user has access to view the comment.

Available since 2021.1.2300

Parameters
: | Name | Type | Description |
: | --- | --- | --- |
: | user |  [User](v1-User.html)  |  The user to check.                     |

Return Value
: | Type | Description |
: | --- | --- |
: |  Boolean  |  When `true`, the specified user has access to view the comment. Otherwise, `false`.                 |

### oldValue

```JAVASCRIPT
oldValue(fieldName)
```

Returns the previous value of a single-value field before an update was applied. If the field is not changed in the transaction, returns `null`.

Parameters
: | Name | Type | Description |
: | --- | --- | --- |
: | fieldName |  string  |  The name of the field.                     |

Return Value
: | Type | Description |
: | --- | --- |
: |  Object  |  If the field is changed in the current transaction, the previous value of the field. Otherwise, `null`.                 |

### required

```JAVASCRIPT
required(fieldName, message)
```

Asserts that a value is set for a field. If a value for the required field is not set, the specified message is displayed in the user interface.

Parameters
: | Name | Type | Description |
: | --- | --- | --- |
: | fieldName |  string  |  The name of the field to check.                     |
: | message |  string  |  The message that is displayed to the user that describes the field requirement.                     |

### was

```JAVASCRIPT
was(fieldName, expected)
```

Checks whether a field was equal to an expected value prior to the current transaction.

Available since 2019.2.55603

Parameters
: | Name | Type | Description |
: | --- | --- | --- |
: | fieldName |  string  |  The name of the field to check.                     |
: | expected |  string  |  The expected value.                     |

Return Value
: | Type | Description |
: | --- | --- |
: |  boolean  |  If the field was equal to the expected value, returns `true`.                 |

## See also

[BaseComment](v1-BaseComment.html) [Set](v1-Set.html) [IssueAttachment](v1-IssueAttachment.html) [User](v1-User.html) [Extension Properties](apps-extension-properties.html) [Issue](v1-Issue.html)

