カスタム・イベントの公開(RecordContext)
RecordContextにカスタム・イベント公開を追加するTypeScriptの例を次に示します:
const publishCustomEvent = async () => {
const frameworkProvider: IUiEventsFrameworkProvider = await CX_SVC_UI_EVENTS_FRAMEWORK.uiEventsFramework.initialize('MyFirstExtensionID','V1');
const payload: ICustomEventRequest = frameworkProvider.requestHelper.createPublishRequest('CustomEvent') as ICustomEventRequest;
payload.setCustomEventName('customEventName');
payload.setEventPayload({ message: 'any data' });
const globalContext: IGlobalContext = await frameworkProvider.getGlobalContext();
globalContext.publish(payload).then((message: IOperationResponse) => {
const response: ICustomEventResponse = message as ICustomEventResponse;
console.log(response.getResponseData());
console.log(response.getResponseData().getData());
console.log(response.getResponseData().getCustomEventName());
}).catch((err) => {
console.log(err);
});
};
JavaScriptの例を次に示します:
const publishCustomEvent = async () => {
const frameworkProvider = await CX_SVC_UI_EVENTS_FRAMEWORK.uiEventsFramework.initialize('MyFirstExtensionID','V1');
const payload = frameworkProvider.requestHelper.createPublishRequest('CustomEvent');
payload.setCustomEventName('customEventName');
payload.setEventPayload({ message: 'any data' });
const globalContext = await frameworkProvider.getGlobalContext();
globalContext.publish(payload).then((message) => {
console.log(message.getResponseData());
console.log(message.getResponseData().getData());
console.log(message.getResponseData().getCustomEventName());
}).catch((err) => {
console.log(err);
});
};
ノート: MSI TabContextに追加されたCustomEventパブリッシュは、そのコンテキストでアクションがサポートされていないためエラーになります。
イベント・サブスクリプションおよび公開を使用すると、UEFでサポートされていないレコードに新しいライフ・サイクル・イベントを定義できます。 特定のレコード・コンテキストのカスタム・イベント・サブスクリプションは、その特定のレコード・コンテキストでカスタム・イベント公開またはVBからのカスタム・イベント・トリガーが発生した場合にのみ通知されます。 その他のレコード・コンテキスト・サブスクリプションは通知されません。 同様に、特定のブラウザ・タブ・コンテキストのカスタム・イベント・サブスクリプションは、その特定のタブ・コンテキストでカスタム・イベント公開またはVBからのカスタム・イベント・トリガーが発生した場合にのみ通知されます。 他のタブ・コンテキスト・サブスクリプションは通知されません。
カスタム・イベントのこの機能により、UEFを介したVB内の外部アプリケーションから外部アプリケーションへの通信も可能になります。