Develop Secure Code
updateViewStat
updateViewStat(articleOrVersionId)Increases the article view count of a KnowledgeArticle or KnowledgeArticleVersion record.
1import { updateViewStat } from "lightning/serviceKnowledgeApi";
2updateViewStat({ articleOrVersionId: string });1/connect/knowledge/article/view-statupdateViewStat uses this Knowledge Article View Stat Resource.
| Parameter Name | Type | Description | Required? |
|---|---|---|---|
articleOrVersionId | String | The ID of the KnowledgeArticle or KnowledgeArticleVersion record. | ![]() |
data— An empty objecterror—FetchResponseThis example shows how you can provide the record context to the articleOrVersionId parameter using @api recordId.
1import { LightningElement, api } from "lwc";
2import { updateViewStat } from "lightning/serviceKnowledgeApi";
3
4export default class Example extends LightningElement {
5 @api recordId;
6
7 increaseArticleViewCount() {
8 updateViewStat({ articleOrVersionId: this.recordId })
9 .then((response) => {
10 this.dispatchEvent(
11 new ShowToastEvent({
12 title: "Success",
13 message: "Article View Count is successfully increased",
14 variant: "success",
15 }),
16 );
17 })
18 .catch((error) => {
19 this.dispatchEvent(
20 new ShowToastEvent({
21 title: "Error updating view count of article",
22 message: error.body.message,
23 variant: "error",
24 }),
25 );
26 });
27 }
28}This button calls the updateViewStat() method.
1<template>
2 <lightning-button
3 variant="brand-outline"
4 label="Increase Article View Count"
5 onclick={increaseArticleViewCount}
6 class="slds-m-left_x-small">
7 </lightning-button>
8 </template>Release Preview