I want to call a UI script from a UI action

bonsai
Mega Sage

I want to call a UI script from a UI action with the script below.

 

The code content is based on product documentation and references.
However, when I run this UI action, I only get a "test" popup.

 

How can I use UI scripts in UI actions?

 

 

UI action

function test_test() {

    alert("test");

    g_ui_scripts.getUIScript('myUIScript').then(function(script) {
        script.myUIScriptMethod();
    }, function() {
        alert('The script did not load');
    });

    alert("test1");
}

 

 

UI script

・UI type: Desktop
・Global: True

(function() {
    return {
        myUIScriptMethod: function() { 
            alert("This is an alert.");
        }
    };
})();

 

 

6 REPLIES 6

IAmAbhigyaan12
Giga Guru

Hi @bonsai  :

If you try below method it might work.

 

UI Script (myUIScript):

This remains the same as you provided in your question. It defines the myUIScriptMethod function.

 

 

// UI Script 
(myUIScript) 
(function() { 
return { myUIScriptMethod: function() 
{ alert("This is an alert."); 
} 
};
})(); 


In your UI action, you should call a client script function instead of directly trying to call the UI script method.

/ UI Action
function callUIScriptMethod() {
// Call a client script function
myClientScriptFunction();
}

 

Now create a client script.
 

 

// Client Script (My Client Script)
function myClientScriptFunction() {
// Call the UI script method
g_ui_scripts.getUIScript('myUIScript').then(function(script) {
script.myUIScriptMethod();
}, function() {
alert('The script did not load');
});
}


// Client Script (My Client Script)
function myClientScriptFunction() {
// Call the UI script method
g_ui_scripts.getUIScript('myUIScript').then(function(script) {
script.myUIScriptMethod();
}, function() {
alert('The script did not load');
});
}

 

If my answer solved your issue, please mark my answer as Correct & hit like Helpful

Thanks
Abi

It didn't work. . .

 

0001.png

0002.png

0003.png

0004.png