Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

Unable to access window and document objects, jQuery, and more using a form UI Action in a scoped application (Helsinki)

artsupsiri
Tera Contributor

Below is a screenshot of a very simple UI Action that uses jQuery to hide some form elements:

Screen Shot 2017-10-11 at 12.43.53 PM.png

It works great when the application scope is Global, but if I create it so that its scope is that of a scoped application, it throws an error: Uncaught TypeError: jQuery is not a function

Looking at the rendered page's source code, the globally-scoped UI Action's JS is rendered as-is on the page:

<script>

function toggleRows(){

jQuery('.section-content .row').toggleClass('hide');

}

</script>

On the other hand, the scoped UI Action's JS seems to have additional code injected, which is what I believe is causing the errors:

<script>

addLoadEvent(function() {

  var toggleRows = (function(GlideAjax,g_form,GlideDialogWindow,GlideRecord,window,document,$,jQuery,$$,$j,$F,gel,undefined){

      "use strict";

      function toggleRows(){

          jQuery('.section-content .row').toggleClass('hide');

      }

      return toggleRows.bind(null)

  })(ScopedGlideAjaxGenerator("x_bonm_bob"),ScopedGFormGenerator("x_bonm_bob"),ScopedGlideDialogWindowGenerator("x_bonm_bob"),null,null,null,null,null,null,null,null,null);

  window.toggleRows = toggleRows;

});

</script>

Any idea what's happening here?

1 ACCEPTED SOLUTION

brianrichards
Tera Guru

In scope we lose access to a number of things. This may not be a thorough explanation / bit o' help, but I recall this community post being helpful to me:



Importing your own jQuery or other client side library for your scoped app



- Brian


View solution in original post

3 REPLIES 3

brianrichards
Tera Guru

In scope we lose access to a number of things. This may not be a thorough explanation / bit o' help, but I recall this community post being helpful to me:



Importing your own jQuery or other client side library for your scoped app



- Brian


Hi Brian,



Creating the system property glide.script.block.client.globals did the trick. Thanks a lot for taking the time to help out!


Setting this property didn't work for me, as described here: Re: Use getElementById in catalog client script



Everywhere I see in this community is people using "scoped" applications.   I never use them, I always use the "Global" scope for everything.  



Does glide.script.block.client.globals ONLY work in "scoped" applications??