1e41f4b71Sopenharmony_ci# Updating Widget Content by Widget Host (for System Applications Only)
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ci
4e41f4b71Sopenharmony_ciWidgets that are updated periodically are subject to the scheduled time or interval settings. To offer more flexible updates, the widget host can provide a button to proactively trigger a widget update. Specifically, the widget host calls the [requestForm](../reference/apis-form-kit/js-apis-app-form-formHost-sys.md#requestform) API to request a widget update. The system then calls the [onUpdateForm](../reference/apis-form-kit/js-apis-app-form-formExtensionAbility.md#onupdateform) lifecycle callback in the FormExtensionAbility of the widget provider. In the callback, the [updateForm](../reference/apis-form-kit/js-apis-app-form-formProvider.md#updateform) API can be used to update the widget content. For details about the **onUpdateForm** lifecycle callback, see [Updating Widget Content Through the message Event](arkts-ui-widget-event-formextensionability.md).
5e41f4b71Sopenharmony_ci
6e41f4b71Sopenharmony_ci```ts
7e41f4b71Sopenharmony_ciimport { formHost } from '@kit.FormKit';
8e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit';
9e41f4b71Sopenharmony_ciimport { hilog } from '@kit.PerformanceAnalysisKit';
10e41f4b71Sopenharmony_ci
11e41f4b71Sopenharmony_cilet storage = new LocalStorage();
12e41f4b71Sopenharmony_ciconst TAG: string = 'Index';
13e41f4b71Sopenharmony_ciconst DOMAIN_NUMBER: number = 0xFF00;
14e41f4b71Sopenharmony_ci
15e41f4b71Sopenharmony_ci@Entry(storage)
16e41f4b71Sopenharmony_ci@Component
17e41f4b71Sopenharmony_cistruct Index {
18e41f4b71Sopenharmony_ci  @StorageLink('formId') formId: number = 0;
19e41f4b71Sopenharmony_ci
20e41f4b71Sopenharmony_ci  build() {
21e41f4b71Sopenharmony_ci    Column() {
22e41f4b71Sopenharmony_ci      Column() {
23e41f4b71Sopenharmony_ci        //...
24e41f4b71Sopenharmony_ci        Button() {
25e41f4b71Sopenharmony_ci          //...
26e41f4b71Sopenharmony_ci        }
27e41f4b71Sopenharmony_ci        .onClick(() => {
28e41f4b71Sopenharmony_ci          hilog.info(DOMAIN_NUMBER, TAG, `FormAbility update form click, formId: ${this.formId}`);
29e41f4b71Sopenharmony_ci          // formId is the ID of the widget to be updated.
30e41f4b71Sopenharmony_ci          formHost.requestForm(this.formId.toString()).then(() => {
31e41f4b71Sopenharmony_ci            hilog.info(DOMAIN_NUMBER, TAG, 'Succeeded in requestForming.');
32e41f4b71Sopenharmony_ci          }).catch((error: BusinessError) => {
33e41f4b71Sopenharmony_ci            hilog.error(DOMAIN_NUMBER, TAG, `requestForm fail, error: ${JSON.stringify(error)}`);
34e41f4b71Sopenharmony_ci          })
35e41f4b71Sopenharmony_ci        })
36e41f4b71Sopenharmony_ci        .margin(5)
37e41f4b71Sopenharmony_ci      }
38e41f4b71Sopenharmony_ci      //...
39e41f4b71Sopenharmony_ci    }
40e41f4b71Sopenharmony_ci    //...
41e41f4b71Sopenharmony_ci  }
42e41f4b71Sopenharmony_ci}
43e41f4b71Sopenharmony_ci```
44