1# Updating Widget Content by Widget Host (for System Applications Only) 2 3 4Widgets 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). 5 6```ts 7import { formHost } from '@kit.FormKit'; 8import { BusinessError } from '@kit.BasicServicesKit'; 9import { hilog } from '@kit.PerformanceAnalysisKit'; 10 11let storage = new LocalStorage(); 12const TAG: string = 'Index'; 13const DOMAIN_NUMBER: number = 0xFF00; 14 15@Entry(storage) 16@Component 17struct Index { 18 @StorageLink('formId') formId: number = 0; 19 20 build() { 21 Column() { 22 Column() { 23 //... 24 Button() { 25 //... 26 } 27 .onClick(() => { 28 hilog.info(DOMAIN_NUMBER, TAG, `FormAbility update form click, formId: ${this.formId}`); 29 // formId is the ID of the widget to be updated. 30 formHost.requestForm(this.formId.toString()).then(() => { 31 hilog.info(DOMAIN_NUMBER, TAG, 'Succeeded in requestForming.'); 32 }).catch((error: BusinessError) => { 33 hilog.error(DOMAIN_NUMBER, TAG, `requestForm fail, error: ${JSON.stringify(error)}`); 34 }) 35 }) 36 .margin(5) 37 } 38 //... 39 } 40 //... 41 } 42} 43``` 44