I want to call a UI script from a UI action
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-03-2023 10:45 PM
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.");
}
};
})();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-04-2023 04:43 AM - edited 09-04-2023 11:27 PM
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();
}
// 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');
});
}
Thanks
Abi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-04-2023 06:40 AM
It didn't work. . .