Generate a Request Object Using requestHelper

To subscribe to app-level events or to perform app-level operations, the external application must be able to invoke subscribe and publish APIs provided by the UI Events Framework.

These APIs will expect a request object which will carry the information about the events to be listened to or operations to be performed. The framework provides a requestHelper object which will enable the user to generate the request object specific to each event or operation.

The following code example shows the syntax for requestHelper object:
IRequestHelper {
    createSubscriptionRequest(eventName: string): IEventRequest;
    createPublishRequest(operationName: string): IOperationRequest;
    }
    IEventRequest {
    getEventName(): string;
    }
    IOperationRequest {
    getOperationName(): string;
    }
The following TypeScript example shows how you generate a request object for an event subscription:
/// <reference path="uiEventsFramework.d.ts"/> 
    const frameworkProvider: IUiEventsFrameworkProvider =
    await CX_SVC_UI_EVENTS_FRAMEWORK.uiEventsFramework.initialize('MyFirstExtensionID');
    const globalContext: IGlobalContext = await frameworkProvider.getGlobalContext();
    const requestObject: IEventRequest = 
frameworkProvider.requestHelper.createSubscriptionRequest('cxEventBusTabOpenEvent');
    globalContext.subscribe(requestObject,(response: IEventResponse) => {
      // custom code
    });
The following JavaScript code sample shows how to generate request object for event subscription:
const frameworkProvider = await 
CX_SVC_UI_EVENTS_FRAMEWORK.uiEventsFramework.initialize('MyFirstExtensionID');
    const globalContext = await  frameworkProvider.getGlobalContext();   
    const requestObject = 
frameworkProvider.requestHelper.createSubscriptionRequest('cxEventBusTabOpenEvent');
     globalContext.subscribe(requestObject,(response) => {
    // custom code
    });
The following TypeScript code sample shows how to generate request object for performing an operation:
/// <reference path="uiEventsFramework.d.ts"/>  
    const frameworkProvider: IUiEventsFrameworkProvider = await CX_SVC_UI_EVENTS_FRAMEWORK.uiEventsFramework.initialize('MyFirstExtensionID');
    const globalContext: IGlobalContext = await frameworkProvider.getGlobalContext();
    const restCallRequest: IServiceConnectionRequest = (frameworkProvider.requestHelper.createPublishRequest('InvokeServiceConnection') as IServiceConnectionRequest);
    restCallRequest.setServiceConnectionId('interactions/update_interactions');
    restCallRequest.setParameters({ "interactions_Id": "12345" });
    restCallRequest.setBody({ "StatusCd": "ORA_SVC_CLOSED" });
    globalContext.publish(restCallRequest).then((message: IOperationResponse) => {
    // custom code
    }).catch((error: IErrorData) => {
    // custom code
    });
The following JavaScript code sample shows how to generate request object for performing an operation:
const frameworkProvider = await CX_SVC_UI_EVENTS_FRAMEWORK.uiEventsFramework.initialize('MyFirstExtensionID');
    const globalContext = await frameworkProvider.getGlobalContext();
    const restCallRequest = (frameworkProvider.requestHelper.createPublishRequest('InvokeServiceConnection'));
    restCallRequest.setServiceConnectionId('interactions/update_interactions');
    restCallRequest.setParameters({ "interactions_Id": "12345" });
    restCallRequest.setBody({ "StatusCd": "ORA_SVC_CLOSED" });
    globalContext.publish(restCallRequest).then((message) => {
          // custom code
          const response = message.getResponseData();
          console.log(response.getStatus());
          console.log(response.getBody());
    }).catch((error) => {
          // custom code
    });