After a callback custom action is added in ThoughtSpot, add an event handler to listen to the callback event and trigger a data payload as a response when a user clicks the callback action in the UI.
In this example, the data payload from the custom action response is logged in the console.
Example code for Answer payloads
searchEmbed.on(EmbedEvent.CustomAction, payload => {
const data = payload.data;
if (data.id === 'show-data') {
console.log('Custom Action event:', data.embedAnswerData);
}
})
Example code to get underlying data using AnswerService
class
Use the AnswerService
class to run GraphQL queries in the context of the Answer on which the custom action is triggered.
searchEmbed.on(EmbedEvent.CustomAction, async e => {
const underlying = await e.answerService.getUnderlyingDataForPoint([
'col name 1'
]);
const data = await underlying.fetchData(0, 100);
})
Example code for Liveboard payload (Classic experience mode)
liveboardEmbed.on(EmbedEvent.CustomAction, payload => {
if (payload.id === 'show-data') {
console.log('Custom Action event:', payload.data);
}
})
Example code for Liveboard data payload (New experience mode)
liveboardEmbed.on(EmbedEvent.CustomAction, payload => {
const customActionId = 'show-data';
if (payload.data.id === customActionId) {
console.log('Custom Action event:', payload.data);
}
})
Example code to fetch large datasets in batches
const data = payload.data;
if (data.id === 'show-data') {
const fetchAnswerData = await payload.answerService.fetchData(1, 5);
//where the first integer is the offset value and the second integer is batchsize
console.log('fetchAnswerData:::', fetchAnswerData);
}