Custom Event Subscription and Publish from VB

Custom event publish request can be listened inside VB and from VB the publish request can be acted upon.

You can either resolve or reject the request to send positive or negative feedback back to the requester. Similarly Custom event can be triggered from VB so any receiver who has added a subscription to it will get a notification with the event data send from VB.

In the Fusion VB application there are two events in the container called uefCustomEvent and triggerUefCustomEvent which are used to to add a listener to a customEvent publish request or to trigger a customEvent from VB respectively:

uefCustomEvent Usage: Listening to and acting upon a Custom Event publish request inside VB

A custom event publish request on top of GlobalContext or on top of TabContext from the same browser tab can be listened ti inside VB and you can write your own logic on that request. You can either resolve or reject this request which will in turn give a positive or negative feed back to the publisher who's publishing the customEvent request.

Here's an example of the structure of the event.event object raised by uefCustomEvent.

{
markFailure: () => {},
markSuccess: (data: any) => {},
requestDetails: {
customEventName: string;
payload: any;
},
objectContext: {
objectId: null,
objectType: null,
tabId: string,
msiTabId: null,
msiSubTabId: null
}
}

Here are the steps:

  1. Add a listener to uefCustomEvent.
  2. In the event object, check the customEventName.
  3. Call the markSuccess or markFailure callbacks which are available in the event object.
  4. MarkSuccess callback execution will give a positive feedback to the customEvent publisher. Any data passed in the markSuccess callback is received at the publisher.
  5. MarkFailure callback execution gives negative feedback to the customEvent publisher.

If you need to call the uefCustomEvent listener in browserTab-1 from another browserTab-2, you can call the publish api on top of browserTab-1's tabContext from browserTab-2 and perform the actions detailed in this step.

triggerUefCustomEvent Usage: Triggering a Custom Event from VB

You can trigger any customEvent from a VB application to allow any application subscribed to the same event to get a notification of it. You can pass any data with this custom event which is received at the receiver where the subscription has been added.

An event named triggerUefCustomEvent in the ServiceCenter container page accepts eventName and payload properties in its event payload object..

Here are the steps:

  1. From an action chain in container-page, call Fire Event block (for example, on a button click, add an action chain that calls Fire Event block in the action chain for the button click).
  2. Select the eventName as triggerUefCustomEvent in page level (container-page)
  3. Select the assign block for the payload object of the event
  4. Give any customEventName in the eventName attribute of the event object.
  5. Give any data as the object in the payload attribute of the event object.

Any application which has added a subscription for the same customEventName will get a notification whenever this action chain block is executed. It will also receive the data passed in the payload attribute. Thus VB can trigger any customEvent and pass data along with it so that any application which is interested in the same customEvent will get the notification and the event data passed from VB.

Note: The event getting triggered from VB is triggered on top of GlobalContext and hence the same can be listened from any browser tabs, which has added a subscription for it on top of globalContext..
UIEventsAPPFramework.UefClient.getUEFProvider().then((CX_SVC_UI_EVENTS_FRAMEWORK) => {
  CX_SVC_UI_EVENTS_FRAMEWORK.uiEventsFramework.initialize('MyFirstExtensionID').then((uefProvider) => {
    uefProvider.getGlobalContext().then((globalContext) => {
      const requestObject = uefProvider.requestHelper.createSubscriptionRequest('cxEventBusTabOpenEvent');
      globalContext.subscribe(requestObject, (response) => {
        console.log('Response from UEF API used in APP Window___', response);
      });
    });
  });
});

Example: Subscribe Field Value Change in VB application window using UEF:

async listenFieldValueChange() {
      const uefProvider = await UIEventsAPPFramework.UefClient.getUEFProvider();  
      const frameworkProvider = await uefProvider.uiEventsFramework.initialize('FVC');  
      const tabContext = await frameworkProvider.getTabContext();
      const recordContext = await tabContext.getActiveRecord();   
      const requestObject =  
      frameworkProvider.requestHelper.createSubscriptionRequest('cxEventBusFieldValueChangeEvent');
      requestObject.setFields(['ServiceRequest.Title','ServiceRequest.ProblemDescription']);

      recordContext.subscribe(requestObject, (response) => {          
          const fieldName = response.getResponseData().getFieldName();
          const newValue = response.getResponseData().getNewValue();
          const oldValue = response.getResponseData().getOldValue();
          console.log(`Field Name: ${fieldName}, oldValue: ${oldValue}, newValue: ${newValue}`);
      });
}