Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

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

Philipp Kriegel
Contributor
January 16, 2023

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

4 votes
Philipp Kriegel
Contributor
March 13, 2023

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>
Robert Mugabuhamye
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
March 13, 2023

Thank you @Philipp Kriegel  

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.
July 7, 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 

0 votes
Robert Mugabuhamye
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
March 10, 2023

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

Thanks

Philipp Kriegel
Contributor
June 21, 2023

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