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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Updating to Jira 9 -> AJS.toInit is not a function

Hi there,

 

currently i'm upgrading a Plugin to JIRA 9.+ and im facing the Problem,

that, what ever i configure AJS isn't loaded. The same happens to jQuery.xyz

 

The AJS.toInit Block is included in the vm template, as well as the required commands.

We also defined a web-resource including AJS as a dependency.

 

$webResourceManager.requireResourcesForContext("com.atlassian.auiplugin:ajs")
$webResourceManager.requireResource("com.atlassian.auiplugin:ajs")
AJS.toInit(function(){
jQuery(document).ready(function() {
doInitialStuff();
});
}); 

 

Does anyone have any suggestions where I can look for the source of the problem?

Thanks

2 answers

With some guidance from the official support i found this as a solution:

In your template add two script sections one as module the other as text/javascript.

The module contains only the AJS.toInit while the other contains all other functions and the check if AJS is defined.

The module block is only executed once, the other is for the remaining runtime.

<script type="module">
AJS.toInit(function(){
jQuery(document).ready(function() {
initStuff();
});
});
</script>



<script type="text/javascript">
function initStuff() {
// do some magic
}

if (typeof jQuery != "undefined") {
jQuery(document).ready(function() {
initStuff();
});
}
</script>
Graham Twine
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.
Jul 07, 2023

If I add both code blocks things run twice.

The module code block is new to me and worked a treat :)

 

Thanks @Philipp Kriegel 

hello @Philipp Kriegel ,
How did you managed to solved this issue ??

Thanks

Hey,

sorry for the late reply. I've missed the notification.

In the end the support of Atlassian asked me to confirm something.

Using the code block from the support with some other blocks i found in other sources i found a solution that worked for us.

Suggest an answer

Log in or Sign up to answer