How to get the spaceKey in a blueprint wizard

(reposted from Solved: how to get the spaceKey to use in the blueprint wi... once I realised the developer community is different to the user community )

In a Confluence blueprint wizard, is it possible to have the spaceKey of the intended page’s space available to the wizard? The user has already chosen which space they intend to create the page in on the previous screen. says that state.spaceKey will have the spacekey if I use setDirectCallback(),. This is true, but the rest of the wizard is ignored. state.spaceKey does not appear to be set in the functions set up by pre-render.page0 and post-render.page0 hooks.



I found a solution.

var spacekey is defined in the global context:

(function ($) {
    var spacekey; //to be set in a callback 

I already had a function registered for the post-render hook:
wizard.on('post-render.page0', postRender0);
In that function, the chosen spaceKey is part of the wizardData:

   function postRender0(e, state) {
        var wizardData = state["wizardData"];
        spacekey = wizardData["spaceKey"];

From here, I can use the spacekey as an index into calls to a database that depends on which space the page will be in.