CS Fire Events Not Working

Is there anything special I need to do to fire events in CS.

cs.fire_event(cs.ref("evt_sys_config_import_success"));

Doing the above results in no detective detail (at all) and nothing is happening as a result of the event being fired.

Does the code studio item need to be in “Record” execution context or should it fire even in “Global” ?

Execution context appears to make no difference at all from my testing.

OK so the answer is that the running Rule (calling the CS object - must have a context - CS based events won’t fire based on Global Action scope rule.

OK so I can kind of work around that by setting a global variable instead and just doing something off the back of that changing - but now im stuck with the problem that I cannot trigger an email message because that requires a context record !!!

Basically the premise here is I want to send either a success or failure message based on some code studio functionality as a result of a snapshot install - it’s an automatic post snapshot configuration setter.

Triggering all of this is perfectly standard but do you think I can find a way to send a “singular” email response afterwards :thinking:

I need to be able to send a message with basically no context (its to a fixed recipient) so has no specific context either.

I have a working solution now.

Since im already logging this activity to an audit log object, I can trigger an email from the specific record being created (under specific subset conditions that matches my needs) so all good :+1:

Just one other final thing I found (and it caught me out for a while).

If you use cs.error() to output a fault in your application - it literally stops at that point - nothing else can be done after the cs.error() call. If you want to do other things - like maybe add an audit log entry - you need to use cs.warn() instead.

Maybe it was just me :stuck_out_tongue_winking_eye:

Hi Haydn, busy weekend by the looks of it!

Just to add that cs.fire_event() only works in scenarios where a context record is already known. I’m not even entirely sure when this is the case or not, so I tend to avoid it and instead use record.fire_event(). Basically the same, but you need to have intentionally created a record instance for the record you want to fire the event on.

E.g.
cs.record(record_id).fire_event(cs.ref('my_event'));