IRecordContext
IRecordContext extends the functionalities of IContext and provides RecordType and RecordId.
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.
subscribe: (requestObject: IEventRequest, callbackFunction: (response: IEventResponse) => void) => ISubscriptionContext;
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
});
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
subscribeOnce: (requestObject: IEventRequest, callbackFunction: (response:IEventResponse) => void) => ISubscriptionContext;
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
});
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.
publish: (requestObject: IOperationRequest) => Promise<IOperationResponse>;
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));
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
dispose:() => void;
recordContext.dispose();
getSupportedEvents
Get the events supported in a record context as an array of strings
getSupportedEvents(): string[];
const supportedEvents: string[] = recordContext.getSupportedEvents();
const supportedEvents = recordContext.getSupportedEvents();
getSupportedActions
Get the actions supported in a record context as an array of strings.
getSupportedActions(): string[];
const supportedActions: string[] = recordContext.getSupportedActions();
const supportedActions = recordContext.getSupportedActions();
getRecordType
Returns the record type of the loaded object in the record context.
getRecordType(): string;
const recordType: string = recordContext.getRecordType();
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.
getRecordId(): string;
const recordId: string = recordContext.getRecordId();
const recordId = recordContext.getRecordId();