What is the difference between context.session['hello'] = {} and context.setVaraible("hello", {})

You asked about setting, not getting. But I think the most interesting difference is on the getting side, where it would affect truthiness. When the variable you are retrieving doesn’t exist, context.session returns undefined while context.getVariable returns null. That’s one of those weird JavaScript things that can trip you up when you’re checking for the existence of something.

On the writing side, it appears that using .session doesn’t show the var in the variables section of a trace. I didn’t poke beyond that to see if there are oddities. I think I’d argue for context.setVariable so I could see what’s happening to it in trace. ((Although the print() function works just fine with either method to dump the content to the Output from All Transactions section of trace.))

¯_(ツ)_/¯

2 Likes