Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,301,546
Community Members
 
Community Events
165
Community Groups

Confluence automation - multiple ajax calls

Dear Automation Atlassians :),

I'm working on a confluence page automation, where I need to perform an ajax call (final call) only after the rest of the (multiple)calls have been done.

Can somebody please guide me?

Below is the code snippet:

AJS.toInit(function () 
{
AJS.$(document).ready(function () {
$.each(product_teams, function () { $.each(this, function (name, value) { // Incidents - Call 1 AJS.$.ajax({ url: `${JIRA_REST_URL}${INCIDENTS}${value}${QUOT}${DURATION}${MAX_RES}`, type: "GET", success: function (data) { if (document.getElementById(`${name}_INCIDENTS`) != null) { document.getElementById(`${name}_INCIDENTS`).innerHTML = JSON.parse(JSON.stringify(data)).total; } }, error: function (err) { console.log(err) } }); }); });
$.each(product_teams, function () { $.each(this, function (name, value) { // Sprint defects - Call 2 AJS.$.ajax({ ..... }); }); });

$.each(teams, function (index, value) { // Final call > final results // Must be executed when Call 1 and Call 2 have finished AJS.$.ajax({ success: function (data) {
}, error: function (err) { console.log(err) } }); });
});});

The problem with the above code is that, the final ajax call is made, even when Call_1 and Call_2 have not yet finished. This results in invalid data.

Option:

$.when(Call_1(), Call_2()).done(function (FinalCall()) {}

doesn't work. Any ideas ?

 

Thanks in advance

Khan

1 comment

May be no-one is interested in my post, but in reality solution is simpler than I thought :)

Here is the simplest solution:

(function () { 
// Function 1 AJS.$.ajax({ url: url, type: "GET", success: function (data) { //do something with the data }, error: function (err) { console.log(err) } });
// Function 2 AJS.$.ajax({ url: url, type: "GET", success: function (data) { //do something with the data }, error: function (err) { console.log(err) } });
});
}) ();

 

Please close this thread

Comment

Log in or Sign up to comment
TAGS
Community showcase
Published in Confluence

An update on Confluence Cloud customer feedback – June 2022

Hi everyone, We’re always looking at how to improve Confluence and customer feedback plays an important role in making sure we're investing in the areas that will bring the most value to the most c...

453 views 2 15
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you