Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Script Include called in Jelly

davide_fais
Tera Expert

Hi ServiceNow Community,

I would call a Script Include by pressing a button. For exemple:

<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">  

<button type="button">Script Include Execution</button>

</j:jelly>

Best Regards,

Davide.

1 ACCEPTED SOLUTION

davide_fais
Tera Expert

I've resolved in this way:



<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">    



<button type="button" onclick="runCode()">Execution</button>



<script>


  function runCode()


  {


  var ga = new GlideAjax('NewIncludeClient');


  ga.addParam('sysparm_name','function1');


  ga.getXMLWait();


  var result=ga.getAnswer();


  alert(result);


  }


  </script>


</j:jelly>


View solution in original post

6 REPLIES 6

Anurag Tripathi
Mega Patron
Mega Patron

Hi Davide,



This is how i do it:



<g:evaluate>


//CALL SCRIPT INCLUDE HERE AND FROM SERVER TAKE THE RETURN VALUE



var temp= new SCRIPTINCLUDE().FUCNTION();


</g:evaluate>



<button type="button">$[temp]</button>


-Anurag

thanks Anurag Tripathi , I've try your code,


but in this way Script Include running always, even if I not press on button.


I would only execute the script when I pressing on Button



<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">  



<g:evaluate var="jvar_gr" object="true">


var temp= new NewInclude().myFunction();



</g:evaluate>



<button type="button">execution $[temp]</button>


 


</j:jelly>


Hi Davide,



You can have your button like below and use a onClick function. This onClick function will be available in the client script part where you can use GlideAJAX to execute your script include.



<input id="buttonID" title="Button" class="button"


  type="button" onclick="functionName();"


  value="btn" />


Brad Tilton
ServiceNow Employee
ServiceNow Employee

I think the button press is always going to end up running client side, so you would need to execute a client side function that uses glideajax to call the script include.