All Apps and Add-ons

(javascript) Context setter : Problem with sideview

Communicator

Dear all,

I've tried to set a token for a $foo$-variable in javascritp using the context.set-method, but it doesn't work as expected - here is an example, what I've done (simplified).

var context = this.getContext();
context.set("foofoo", "bla"); 
console.log(context); // Within that object - "foofoo" is set to "bla"
var context1 = this.getContext();
console.log(context1); // no "foofoo" key

I'm new at developing with sideview, so I think, I missed some methods or I have a logical knot in my brain 🙂

Please help!
Thx, Robert

SplunkTrust
SplunkTrust

Well if you're beginning at this level writing custom JS, you're not really doing it the right way. Even CustomBehavior JS is something that Sideview users only use in extreme circumstances, and CustomBehavior JS is a lot more scoped than raw Javascript that tries to patch the system.

So I'd take a step back and read the Sideview docs, ask a separate question about what you're trying to do. Often I find people trying to make a custom module when they can get the same goal achieved with the out-of-the-box modules. It's not always obvious how odd modules like ValueSetter ResultsValueSetter and Multiplexer et al can work together to do "strange" use cases, but between all of them, they cover a lot of ground.

But... to answer your direct question, the way you change the context for downstream modules is by returning the modified context object from a module's getModifiedContext method. That is the only (sane) way. You can think of getContext() as "give me the context that rolls up everything all my upstream modules know about the world". And getModifiedContext() as "if/when my downstream modules asked me for a context, what do I give them".

and one more thing - if you really do end up needing some custom JS for your use case, you should start with the CustomBehavior stuff. It'll me harder to shoot yourself in the foot and it'll make your code a little cleaner compared to raw JS.

0 Karma

SplunkTrust
SplunkTrust

OK. So you're already a pretty advanced Sideview/Splunk user if you're comfortable with the Table Embedding feature and you're able to make a custom module. Awesome. To grab values like $row.field.fieldName$, you'll get a context with this.getContext(), and then call `context.get("row.fields.fieldName"). On the other hand to pass new key values downstream, you need to keep selected bits and bobs as internal properties an dthen implement getModifiedContext() on your custom module. Within your getModifiedContext, get a context, set() the keys, and return the context.

0 Karma

Communicator

Dear Nick,
thank you for your support!
As I said, I'm not very familiar with all that sideview-moduls, but I try to learn more 🙂

Regarding that usecase I need :

  • a (custom)
    overlay (modal dialog) which opens on click within a table-cell, I have already a module for that.
  • grab the $row.fields$ and display custom actions within that modal - eg. link to other pages/views with the selected $row.fields$ OR downstream to other moduls (in my case eg. a switcher/redirector/postprocess module) or like the pulldown-module to "filter" the table.
  • Hope you can help me!
    Kind regards, Robert

0 Karma