Is it possible to set publishing scope on calls to skuid.events.publish(event, data) ?

  • 1
  • Question
  • Updated 5 months ago
  • Answered
Hello I would like to publish an event to send data from a skuid aggregate model to a lightning component.

skuid.events.publish('AggMessage', JSON.stringify(payload));

AggMessage is never making it to the component listing on 

<aura:handler event="skuid:event" action="{!c.handleSkuidEvent}"/>

I'm assuming this is because the publishing scope of AggMessage needs to be set to "All active pages and Lightning Components"  How do I set event scope from code?

Thanks,
Peter
Photo of Peter Ogilvie

Peter Ogilvie

  • 370 Points 250 badge 2x thumb

Posted 6 months ago

  • 1
Photo of Peter Ogilvie

Peter Ogilvie

  • 370 Points 250 badge 2x thumb
Here's another alternative/related question.

I made the event below with the builder with publish to Lightning Components scope and my component is receiving it. How do I add data payload to this event?

<action type="publish" scope="global" event="UpdateAggriate">
                            <params/>
</action>

Thanks,
Peter
(Edited)
Photo of Zach McElrath

Zach McElrath, Employee

  • 49,056 Points 20k badge 2x thumb
You can add Parameters by clicking the "+" icon on the Publish Event action. This lets you provide key-value pairs of data that is sent to the Lightning Component as an object.
Photo of Peter Ogilvie

Peter Ogilvie

  • 370 Points 250 badge 2x thumb
Fantastic!   When I click on the disk icon to select a field to use as a value doesn't popup anything?   I'm not sure what syntax I should use for the </> button.   How do I add a field from an aggregate model?
Photo of Zach McElrath

Zach McElrath, Employee

  • 49,056 Points 20k badge 2x thumb
If you want to pull in a Model field as a value, you can use {{{$Model.YourModelName.data.0.The_Field_You_Want__c}}}
(Edited)
Photo of Peter Ogilvie

Peter Ogilvie

  • 370 Points 250 badge 2x thumb
It worked!   Thank you so much!
Photo of Zach McElrath

Zach McElrath, Employee

  • 49,056 Points 20k badge 2x thumb
The "Publish Event" action type in the Action Framework is the highly recommended way to set the publishing scope to "All active Skuid Pages and Lightning Components". Technically yes it is possible to specify the scope via the JavaScript API but we'd like to avoid customers using that unless for some reason using the declarative "Publish Event" action is not working.
Photo of Louis Skelton

Louis Skelton

  • 4,878 Points 4k badge 2x thumb
Hi Zach... I'm having to trigger an event from an html submit button in a Skuid template component which the Lightning component can listen for.

My current approach is to listen for an event locally on the Skuid page (skuid.events.publish('some.event')) and to then use an event-triggered sequence in Skuid to listen to this and then publish another event via the action-framework to the surrounding Lightning Component using the broader scope.

This is working fine but it'd be nice to know how to publish to the broader scope straight from javascript rather than using the above two-step process. Any chance you could spill the beans on this?

Just a note - I also found that you had to set the even-triggered sequence to "All Active Pages and Lightning Components" for the above listener to work - even though the javascript was publishing the event from a snippet in the same Skuid page.
Photo of Louis Skelton

Louis Skelton

  • 4,878 Points 4k badge 2x thumb
An alternative approach would be to be able to trigger an event-triggered sequence from within a snippet/javascript
Photo of Peter Ogilvie

Peter Ogilvie

  • 370 Points 250 badge 2x thumb
OK, I'm hopeful!   Thanks! Peter
Photo of Zach McElrath

Zach McElrath, Employee

  • 49,056 Points 20k badge 2x thumb
I'll go ahead and post the way to set publishing scope to "All Skuid Pages and Lightning Components" via JavaScript:

skuid.events.publish("AggMessage", [payload], { scope: skuid.constants.EVENT_SCOPES.GLOBAL });
Photo of Louis Skelton

Louis Skelton

  • 4,878 Points 4k badge 2x thumb
Thank you!!!! :)