# `updateViewStat(articleOrVersionId)`

Increases the article view count of a [KnowledgeArticle](https://developer.salesforce.com/docs/atlas.en-us.knowledge_dev.meta/knowledge_dev/sforce_api_objects_knowledgearticle.htm) or [KnowledgeArticleVersion](https://developer.salesforce.com/docs/atlas.en-us.knowledge_dev.meta/knowledge_dev/sforce_api_objects_knowledgearticleversion.htm) record.

## Syntax

```javascript
import { updateViewStat } from "lightning/serviceKnowledgeApi";
updateViewStat({ articleOrVersionId: string });
```

## Knowledge API Resource

```html
/connect/knowledge/article/view-stat
```

`updateViewStat` uses this [Knowledge Article View Stat Resource](https://developer.salesforce.com/docs/atlas.en-us.chatterapi.meta/chatterapi/connect_resources_knowledge_article_view_stats.htm).

## Parameters

| Parameter Name       | Type   | Description                                                       | Required?                                                                         |
| -------------------- | ------ | ----------------------------------------------------------------- | --------------------------------------------------------------------------------- |
| `articleOrVersionId` | String | The ID of the KnowledgeArticle or KnowledgeArticleVersion record. | ![Yes](https://a.sfdcstatic.com/developer-website/sfdocs/lwc/media/checkmark.png) |

## Returns

- `data`— An empty object
- `error`—[FetchResponse](/docs/platform/lwc/guide/data-error.md)

## Usage

This example shows how you can provide the record context to the `articleOrVersionId` parameter using `@api recordId`.

```javascript
import { LightningElement, api } from "lwc";
import { updateViewStat } from "lightning/serviceKnowledgeApi";

export default class Example extends LightningElement {
  @api recordId;

  increaseArticleViewCount() {
    updateViewStat({ articleOrVersionId: this.recordId })
      .then((response) => {
        this.dispatchEvent(
          new ShowToastEvent({
            title: "Success",
            message: "Article View Count is successfully increased",
            variant: "success",
          }),
        );
      })
      .catch((error) => {
        this.dispatchEvent(
          new ShowToastEvent({
            title: "Error updating view count of article",
            message: error.body.message,
            variant: "error",
          }),
        );
      });
  }
}
```

This button calls the `updateViewStat()` method.

```sfdocs-code {"lang":"html", "title": "", "src": "" }
<template>
   <lightning-button
       variant="brand-outline"
       label="Increase Article View Count"
       onclick={increaseArticleViewCount}
       class="slds-m-left_x-small">
   </lightning-button>
 </template>
```
