Missed Team ’24? Catch up on announcements here.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How to get page id of specific page in java script?

Merijn de Jonge September 22, 2015

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?

2 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

2 votes
Volodymyr Krupach
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 22, 2015

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
Merijn de Jonge September 22, 2015

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).

Volodymyr Krupach
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 22, 2015

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"); } });

Alex Medved _ConfiForms_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 23, 2015

Thanks for the code snipet, @Volodymyr Krupach CQL is cool, yes

Merijn de Jonge September 24, 2015

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?

Volodymyr Krupach
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 24, 2015

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); } ... });

Merijn de Jonge September 24, 2015

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.

Merijn de Jonge September 28, 2015

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.

0 votes
Jobin Kuruvilla [Adaptavist]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 22, 2015

try AJS.params.pageId.

Merijn de Jonge September 22, 2015

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.

TAGS
AUG Leaders

Atlassian Community Events