HI,
I need to get the page id of a particular page in java script. (see also my related question https://answers.atlassian.com/questions/30541689).
Actually, I'm looking for something like:
AJS.getPageId("MyPageName");
can anyone help?
Community moderators have prevented the ability to post new answers.
Hi Merijn,
I guess there is no direct JS method to do this however you can utilize /rest/api/content/search REST API method. Did not test it but should work:
cql=type=page and title=MyPageName
Hi Volodymyr, Thanks for your reaction. I'm new to Confluence, using the rest api sound pretty complicated to me. Could you be so kind to explain in a little more detail about how to use the rest api from within the submit callback in java script? I'm creating a blueprint and when a new page is created I must set the parent page to a specific page (actually to the space home page).
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Here is JavaScript REST API call sample: $.ajax({ type: "GET", url: "http://CONFLUENCE_URL/rest/api/content/search?cql=type=page and title=MyPageName", contentType:"application/json; charset=utf-8", dataType: "json", success: function (dataResp, textStatus, jqXHR){ alert(dataResp); }, error : function(jqXHR, textStatus, errorThrown{ alert("error"); } });
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for the code snipet, @Volodymyr Krupach CQL is cool, yes
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Almost there! One thing I can't figure out. The ajax call is asynchronous. At the moment it is completed and the callback is called in which I set the parentPageId, the newly created page has already a parentPageId assigned and setting it in the callback has no effect. Is there a way to let the submit callback in the page creation process wait for the ajax call to complete?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I am not sure that I follow you but guess that you can put the code "that should wait for the callback" into the callback: $.ajax({ ... success: function (dataResp, textStatus, jqXHR){ // YOUR CODE HERE alert(dataResp); } ... });
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I execute the ajax call in the submit callback when creating a page from a blue print. I.e., Confluence.Blueprint.setWizard('my-blueprint-item', function(wizard) { wizard.on('submit.myWizardId', function(e, state) { AJS.$.ajax(...); }); }); The problem the submit callback will continue when the ajax call is pending. As a consequence the page is created with the default parentPageId. When my ajax call completes it is too late to set the parentPageId. Therefore the challenge is how to let the submit callback wait for the ajax call to compete? I found a workaround my making the ajax call in the post-render callback, which is also part of the page creation process. This works, but is not fully satisfactory.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Based on the answers on this question, I have formulated an answer on my other question here https://answers.atlassian.com/questions/30541689/answers/30941612?flashId=-911090298.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
try AJS.params.pageId
.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Jobin, Thanks for your help. I was aware of your solution, but in my case it won't help. That is because I'm not looking for the page id of the current page but for the id of an arbitrary page. So I'm looking for something like { AJS.getPageId("MyPageName"); } I've reflected this in my question to make it more clear.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.