yuichirio_ha - how to know when to trigger upda...
# dev-help
y
how to know when to trigger updateFilters on liveboard embed once it loads - I want to trigger as soon as liveboard loads for specific users.
a
message has been deleted
s
liveboardId: 'your-liveboard-id', } ); liveboardEmbed.on(EmbedEvent.LiveboardRendered, () => { liveboardEmbed.trigger(HostEvent.UpdateFilters, { filters: [ { column: 'region', oper: 'EQ', values: ['West'], }, ], }); }); liveboardEmbed.render(); ``` Suggestions: - If the filter value is already known before render, prefer setting filters at load configuration time instead of waiting for load-time events. That avoids event sequencing entirely. - Use
UpdateFilters
only for existing Liveboard filters. If you need to apply or change runtime filters, use
HostEvent.UpdateRuntimeFilters
instead. -
LiveboardRendered
is documented as “Emitted when the Liveboard shell loads” and can be used as a hook to trigger other events. - For the most robust “fire as soon as available” behavior, use: -
useHostEventsV2: true
-
liveboardEmbed.subscribedEvent(HostEvent.UpdateFilters)
- If multiple users need different filters, keep that logic in your app and only call
trigger(...)
for the users who match your condition. Docs: - Embed a Liveboard: https://developers.thoughtspot.com/docs/embed-liveboard#_register_handle_and_trigger_events - Embed events: https://developers.thoughtspot.com/docs/embed-events - `EmbedEvent.LiveboardRendered`: https://developers.thoughtspot.com/docs/Enumeration_EmbedEvent#_liveboardrendered - Filters overview / `UpdateFilters`: https://developers.thoughtspot.com/docs/filters-overview#_updatefilters_event - Host events: https://developers.thoughtspot.com/docs/host-events#_retrieving_and_updating_filters
Solution: Use
EmbedEvent.LiveboardRendered
as the normal hook to trigger
HostEvent.UpdateFilters
right after the Liveboard shell is rendered. If your goal is “trigger as soon as it’s ready, without timing issues”, the more reliable pattern is to listen for the host-event subscription signal using
subscribedEvent(HostEvent.UpdateFilters)
and then call
trigger(HostEvent.UpdateFilters, ...)
. The official example specifically calls this the readiness pattern for triggering host events at load time, and it requires
useHostEventsV2
.
Copy code
js
import {
  init,
  AuthType,
  LiveboardEmbed,
  EmbedEvent,
  HostEvent,
} from '@thoughtspot/visual-embed-sdk';

init({
  thoughtSpotHost: 'https://your-instance.thoughtspot.cloud',
  authType: AuthType.None,
});

const currentUser = {
  id: 'u123',
  role: 'regional_manager',
};

const shouldApplyUserFilters = currentUser.role === 'regional_manager';

const liveboardEmbed = new LiveboardEmbed(
  document.getElementById('ts-embed'),
  {
    liveboardId: 'your-liveboard-id',
    useHostEventsV2: true,
  }
);

if (shouldApplyUserFilters) {
  const subscribed = liveboardEmbed.subscribedEvent(HostEvent.UpdateFilters);

  const applyFilters = () => {
    liveboardEmbed.trigger(HostEvent.UpdateFilters, {
      filters: [
        {
          column: 'region',
          oper: 'EQ',
          values: ['West'],
        },
      ],
    });
  };

  liveboardEmbed.on(subscribed, applyFilters);
}

liveboardEmbed.on(EmbedEvent.LiveboardRendered, () => {
  console.log('Liveboard rendered');
});

liveboardEmbed.render();
If you want the simpler event-based approach, this is also supported: ```js import { init, AuthType, LiveboardEmbed, EmbedEvent, HostEvent, } from '@thoughtspot/visual-embed-sdk'; init({ thoughtSpotHost: 'https://your-instance.thoughtspot.cloud', authType: AuthType.None, }); const liveboardEmbed = new LiveboardEmbed( document.getElementById('ts-embed'), {
j
@yuichirio_ha did that help ?
y
yes, Thanks.
j
let me know if anything else is needed