Hi,
I've created a blueprint and I want all pages that are generated from it have the space homepage as parent.
I've seen that you can set the parentPageId from within the submit callback, something like
Confluence.Blueprint.setWizard('myBlueprint:my-item', function(wizard) { wizard.on('submit.myWizardId', function(e, state) { state.wizardData.parentPageId = yourParentPageId }); });
The only thing that needs to be done is to determine the id of the space homepage. I can access the space key and space name, but I don't know how to get the homepage id from these.
Question 1: is the approach I'm following the right way to go? If not, what would be a better way?
Question 2: How to get the page id in the above java script code, given that I know the space key and space name?
Thanks in advance,
Merjn
Community moderators have prevented the ability to post new answers.
Based on the information of https://answers.atlassian.com/questions/30933897 I came to the following approach.
I've created a method setParentPageIdToSpaceHomePageId that makes an ajax call to the server to find the pages of the space. Since the space home page is the first page created, it will have to lowest id (this is an assumption, please let me know if there is a better way). So, from the list of pages I simply select the one with lowest page id. I then set the property parentPageId in the object wizardData to this id. This is the code of setParentPageIdToSpaceHomePageId:
/** * This function sets the parentPageId of wizardData to the page id of the space homepage * @param {} wizardData * @returns {} */ function setParentPageIdToSpaceHomePageId(wizardData) { var spaceKey = AJS.Meta.get("space-key"); AJS.$.ajax({ type: "GET", url: AJS.contextPath() + "/rest/api/content/search?cql=space=" + spaceKey + "%20and%20type=page", contentType: "application/json; charset=utf-8", dataType: "json", success: function(dataResp, textStatus, jqXHR) { var pages = dataResp.results; // heuristic: homepage is first page created in space and therefore has lowest page id. var homePage = pages.reduce(function(prev, cur) { return prev.id > cur.id ? cur : prev }); wizardData.parentPageId = homePage.id; }, error: function(jqXHR, textStatus, errorThrown) { alert("error" + errorThrown); } }); } });
Since the ajax call is asynchronous, I can't call this method from the submit callback (although that would have my preference). The problem is that the submit method completes before setParentPageIdToSpaceHomePageId. Setting parentPageId will then have no effect. Therefore, I make the call to setParentPageIdToSpaceHomePageId in the post-render method, like this:
Confluence.Blueprint.setWizard('myBlueprint:my-blueprint-item', function(wizard) { wizard.on('post-render.myBlueprintWizardId', function (e, state) { setParentPageIdToSpaceHomePageId(state.wizardData); }); });
I'm not a java-script expert and really inexperienced in confluence programming so if you have suggestions for improvement, please let me know.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.