IRecordContext

IRecordContext extends the functionalities of IContext and provides RecordType and RecordId.

Here's the interface:
export interface IRecordContext extends IContext {
     getRecordType(): string;
     getRecordId(): string;
  }

Functions

subscribe

Use this API to subscribe to an event from the Service Center. Using this API, the external application is able to listen to the object level events from the Service Center. Once an event is subscribed using this API, an external application will be notified until the subscription is disposed.

The following sample shows the syntax for subscribe:
subscribe: (requestObject: IEventRequest, callbackFunction: (response: IEventResponse) => void) => ISubscriptionContext;
The following is a code sample in Typescript.
const requestObject: IFieldValueChangeEventRequest = this.frameworkProvider.requestHelper.createSubscriptionRequest('cxEventBusFieldValueChangeEvent') as IFieldValueChangeEventRequest;
  requestObject.setFields(['objectType.fieldnameOne', 'objectType.fieldnameTwo', 'objectType.fieldnameThree']);
  let subscription: ISubscriptionContext = await recordContext.subscribe(requestObject, (eventResponse: IEventResponse) => {
    // eventResponse
  });
  
The following is a code sample in Javascript.
const requestObject = this.frameworkProvider.requestHelper.createSubscriptionRequest('cxEventBusFieldValueChangeEvent');
  requestObject.setFields(['objectType.fieldnameOne', 'objectType.fieldnameTwo', 'objectType.fieldnameThree']);
  let subscription = await recordContext.subscribe(requestObject, (eventResponse) => {
    // eventResponse
  });

subscribeOnce

Subscribe once to a record level event from the Fusion application. For example, a Field Value Change event. The subscription is disposed once the event is fired and the call back is executed

The following code sample shows the syntax:
subscribeOnce: (requestObject: IEventRequest, callbackFunction: (response:IEventResponse) => void) => ISubscriptionContext; 
The following is a code sample in Typescript:
const requestObject: IFieldValueChangeEventRequest = this.frameworkProvider.requestHelper.createSubscriptionRequest('cxEventBusFieldValueChangeEvent') as IFieldValueChangeEventRequest;
  requestObject.setFields(['objectType.fieldnameOne', 'objectType.fieldnameTwo', 'objectType.fieldnameThree']);
  let subscription: ISubscriptionContext = await recordContext.subscribeOnce(requestObject, (eventResponse: IEventResponse) => {
    // eventResponse
  });
The following is a code sample in JavaScript:
const requestObject = this.frameworkProvider.requestHelper.createSubscriptionRequest('cxEventBusFieldValueChangeEvent');
  requestObject.setFields(['objectType.fieldnameOne', 'objectType.fieldnameTwo', 'objectType.fieldnameThree']);
  let subscription = await recordContext.subscribeOnce(requestObject, (eventResponse) => {
    // eventResponse
  });

publish

Publish an operation at the record Context. For example, set a value of a particular field.

The following code sample shows the syntax:
publish: (requestObject: IOperationRequest) => Promise<IOperationResponse>;
The following is a code sample in Typescript:
const requestObject: ISetFieldValueOperationRequest = this.frameworkProvider.requestHelper.createPublishRequest('cxEventBusSetFieldValueOperation') as ISetFieldValueOperationRequest;
  requestObject.field().setValue('objectType.fieldName', 'a value that matches type of field name');
  recordContext.publish(requestObject).then((response: IOperationResponse) => {
           console.log((response as ISetFieldValueResponse).getResponseData().getMessage());
  }).catch((error) => console.log(error));
The following is a code sample in JavaScript:
const requestObject = this.frameworkProvider.requestHelper.createPublishRequest('cxEventBusSetFieldValueOperation');
  requestObject.field().setValue('objectType.fieldName', 'a value that matches type of field name');
  recordContext.publish(requestObject).then((response) => {
           console.log(response.getResponseData().getMessage());
  }).catch((error) => console.log(error));

dispose

Subscribe to a record level event from the Fusion application. For example, a Field Value Change event.
dispose:() => void;
The following code sample shows an example in Typescript and JavaScript:
recordContext.dispose();

getSupportedEvents

Get the events supported in a record context as an array of strings

The following code sample shows the syntax:
getSupportedEvents(): string[];
The following code sample shows example in Typescript.
const supportedEvents: string[] = recordContext.getSupportedEvents();
The following code sample shows example in Javascript.
const supportedEvents = recordContext.getSupportedEvents();

getSupportedActions

Get the actions supported in a record context as an array of strings.

The following code sample shows the syntax:
getSupportedActions(): string[];
The following code sample shows example in Typescript.
const supportedActions: string[] = recordContext.getSupportedActions();
The following code sample shows example for getSupportedActions in Javascript.
const supportedActions = recordContext.getSupportedActions();

getRecordType

Returns the record type of the loaded object in the record context.

The following code sample shows the syntax:
getRecordType(): string;
The following code sample shows an example in Typescript.
const recordType: string = recordContext.getRecordType();
The following code sample shows an example in Javascript.
const recordType = recordContext.getRecordType();

getRecordId

Returns the record ID. For a record context of a record not created yet, the ID will be a negative number.

The following code sample shows the syntax:
getRecordId(): string;
The following code sample shows an example in typescript to getRecordId:
const recordId: string = recordContext.getRecordId();
The following code sample shows an example in JavaScript to getRecordId:
const recordId = recordContext.getRecordId();