The CreatorCon Call for Content is officially open! Get started here.

[SOLVED] How to call scoped UI script from catalog client script ?

JG6
Kilo Guru

It looks like a recurring question, but none of the advised solutions seem to work. Therefor I'd like to present my case.

Can somebody help to find out what I am missing ?

(1) UI Script

  • application: foo
  • name: bar
  • API name: foo.bar
  • ui type: all
  • script
var foo = foo || {};

foo.bar = (function() {
	"use strict";

	return {

		helloWorld: function() {
			console.warn("It works !");
		},
		
		type:  "bar"
	};
})();

(2) Catalog client script (also application 'foo'):

  • g_ui_scripts.getUIScript('foo.bar') => "No script registered with name ..."
  • g_ui_scripts.getUIScript('foo') => "No script registered with name ..."
  • g_ui_scripts.getUIScript('bar') => "No script registered with name ..."
  • g_ui_scripts.getUIScript('foo.bar.helloWorld') => "No script registered with name ..."
  • Same with g_ui_scripts[ ... ] => undefined
  • ScriptLoader.runScripts( ... ) => ScriptLoader undefined
  • ...
1 ACCEPTED SOLUTION

JG6
Kilo Guru

! SOLVED !

By carefully debugging the JS code in the catalog item page it became apparent why it doesn't work. The code of the UI script is expected to be executable. The ui script is the result of this invocation. The bottom line is that the proposed default ui script template is invalid for a scope ui script.

My example should therefore be rewritten as:

(function() {
	"use strict";

	return {

		helloWorld: function() {
			console.warn("It works !");
		},
		
		type:  "bar"
	};
})();

And the invocation:

g_ui_scripts.getUIScript('foo.bar').then(function(script) {
   script.helloWorld();
});

When saving the ui script for the first time there will be a warning about invalid implementation of the ui script. I ignored the error because there is no other way to implement the script for it to be accepted. 

Hope this helps other people too.

View solution in original post

15 REPLIES 15

G24
Kilo Sage

This may be the answer that you were looking for:

UI Script - Global checkbox = false - Application = Global