Generate request object using requestHelper

To subscribe to app-level events or to perform app-level operations, the external application must invoke the Subscribe or Publish APIs provided by the UI Events Framework.

These APIs will expect a request object that contains the details of the events to be listened to or operations to be performed. UEF provides a requestHelper object to generate the request object specific to each event pt operation.

Structure of the requestHelper object

IRequestHelper {
    createSubscriptionRequest(eventName: EventName): IEventRequest;
    createPublishRequest(operationName: OperationName): IOperationRequest;
}
IEventRequest {
    getEventName(): string;
}
IOperationRequest {
     getOperationName(): string;
}

Code samples

Here are examples of generating the request object for an event subscription.

Here's a Typescript example:

const frameworkProvider: IUiEventsFrameworkProvider = await CX_SVC_UI_EVENTS_FRAMEWORK.uiEventsFramework.initialize('MyFirstExtensionID','V1');
    const globalContext: IGlobalContext = await frameworkProvider.getGlobalContext();
    const requestObject: IEventRequest = frameworkProvider.requestHelper.createSubscriptionRequest('cxEventBusTabOpenEvent');
    globalContext.subscribe(requestObject,(response: IEventResponse) => {
      // custom code
    });

Here's a Javascript example:

const frameworkProvider = await CX_SVC_UI_EVENTS_FRAMEWORK.uiEventsFramework.initialize('MyFirstExtensionID','V1');
const globalContext = await frameworkProvider.getGlobalContext();    
const requestObject = frameworkProvider.requestHelper.createSubscriptionRequest('cxEventBusTabOpenEvent');
globalContext.subscribe(requestObject,(response) => {
    // custom code
});

Here are examples of generating a request object for performing and operation.

Here's a Typescript example:

const frameworkProvider: IUiEventsFrameworkProvider = await CX_SVC_UI_EVENTS_FRAMEWORK.uiEventsFramework.initialize('MyFirstExtensionID','V1');
    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
    }); 

Here's a Javascript example:

const frameworkProvider = await CX_SVC_UI_EVENTS_FRAMEWORK.uiEventsFramework.initialize('MyFirstExtensionID','V1');
    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
    });