UI Script with onLoad and onChange client scripts

exprozor
Tera Contributor

Hello everyone

I've been trying to get a UI script working without not much of a success.

SN's documentation in this regards do not cover all aspects of its potential usage. I've gone through all forum posts here, including: this and many others

Can anyone suggest what am I doing wrong ?
UI Script

<scope> = <scope> || {};

<scope>.<name>= (function initializeLibrary(g_form) {

    var _localVariable = '';

    function _localFunction() {
      //do something
    }

    function _localFunction2() {
       //do something
    }
	
    var functionToCall= function doProcessChanges(fieldName) {
         //call local functions
         //call AJAX
	
	};

    return {
        processPhasingChanges: functionToCall
	};
		
})(g_form);

onLoad Client Script order - 100
ScriptLoader.getScripts('<scope>.<name>.jsdbx');

onChange Client Script: order - 200
tried all variations, such as

  • <scope>.<name>.processPhasingChanges
  • processPhasingChanges
  • <name>.processPhasingChanges

None seems to work. Any help is much appreciated

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

check out these links which have solution

How to call UI Scripts from Client Scripts

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

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

7 REPLIES 7

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

check out these links which have solution

How to call UI Scripts from Client Scripts

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

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

exprozor
Tera Contributor

Thanks @Ankur Bawiskar 
tried using

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

but I get onChange script error: ReferenceError: g_ui_scripts is not defined function() { [native code] }Note that both my UI script and Client script is in scope

Hi,

I remember I used either of the link to get it work

try the 2nd link

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

exprozor
Tera Contributor

None of them works in my case... it's just kind of sad there is almost no documentation available and you have to spend hours to get the syntax working...