Forums

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

how can we run a java script in ifttt when the page initially loads

sai sreekar
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!
June 2, 2025

So i am trying to make a js to run when the page loads initially but am failing to trigger it. confiform.png

not sure where i am failing 

my js looks like this 

<script type="text/javascript">

AJS.toInit(function() {
  console.log("Script loaded and running in AJS context!");

  var nameFieldName = "ProductGroup";
  var emailFieldName = "recipientEmail";

  var emailMap = {
    "john": "john.dow@gmail.com",
    "team": "team.all@gmail.com",
    "mary": "mary.pop@gmail.com"
    
  };

  var nameField = document.querySelector('[name="' + nameFieldName + '"]');
  var emailField = document.querySelector('[name="' + emailFieldName + '"]');

  console.log("Dropdown field:", nameField);
  console.log("Email field:", emailField);

  if (nameField && emailField) {
    function updateEmail() {
      var selectedID = nameField.value;
      var email = emailMap[selectedID] || "";
      console.log("Selected:", selectedID, "Setting email:", email);
      emailField.value = email;
    }

    nameField.addEventListener('change', updateEmail);
    updateEmail();
  } else {
    console.log("Fields not found. Double-check field names.");
  }
});

</script>

 

ps. it runs fine if i try to manually run it via console 

2 answers

1 accepted

2 votes
Answer accepted
Alex Medved _ConfiForms_
Community Champion
June 3, 2025

Hi @sai sreekar 

IFTTT in ConfiForms is triggered as a result of the form submit - it cannot run on page load

If you want your JavaScript to run on page load then just put it to run on a page load - https://support.atlassian.com/confluence/kb/how-to-use-javascript-in-confluence/

Alex

sai sreekar
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!
June 3, 2025

Good Morning @Alex Medved _ConfiForms_ 

when you said just put run on page load do you mean the Fire IFTTT action only when this condition/filter is met and if yes what can i put for to run it on page load and if not can you please tell me 

Thank you 

Alex Medved _ConfiForms_
Community Champion
June 3, 2025

What I am saying is that if you want to run some JavaScript on a page load then there is no need for ConfiForms

sai sreekar
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!
June 3, 2025

Good Morning @Alex Medved _ConfiForms_ 

I have tried to use the HTML macro but i was not able to trigger it, i have tried to put in at the top which is not even in the confiform or in between the confiforms. And also in confluence when i try to add it in the macro it was never running it when the page loaded.

 

Thank you 

sai sreekar
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!
June 3, 2025

it worked @Alex Medved _ConfiForms_ 

i had to run it before the confiform, as part of confluence, i was trying to add it in the confiform and was expecting it to work 

 

Thank you so much @Alex Medved _ConfiForms_  

Alex Medved _ConfiForms_
Community Champion
June 5, 2025

Yes, you need to have an HTML macro outside of ConfiForms macro, to be part of the page

0 votes
Charlie Misonne
Community Champion
June 3, 2025

Hi @sai sreekar and welcome to the Atlassian Community!

Do you have other IFTT macros where the javascript is executed?

According to the plugin's documentation running javascript could be disabled in the general settings of the app.

Administrators could restrict this in ConfiForms general settings

Can you check this?

 

 

sai sreekar
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!
June 3, 2025

Good Morning @Charlie Misonne 

i have other pages where the other js are working, i am not sure if that changes with each page , but if doesnot that should be any issue 

Thank you 

 

 

Charlie Misonne
Community Champion
June 3, 2025

Ok then my suggestion does not apply.

@Alex Medved _ConfiForms_ 's answer is more on point since he seems to be working for the plugin vendor.

Like sai sreekar likes this
sai sreekar
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!
June 3, 2025

Thank you @Charlie Misonne 

Like Charlie Misonne likes this

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events