How to create a UI Script as .jsdbx and call it from UI Action

Tschewski
Giga Contributor

Hi experts,

I have the requirment to call a ui script (.jsdbx) from a ui action in problem process.

I created the ui action:

find_real_file.png

function onAssess() {
    if (g_form && g_form.mandatoryCheck()) {
        ScriptLoader.getScripts('TestUiScripts.jsdbx', function() {
            TestUiScripts.testAlert();
        });
    }
}

 

...and I created a UI script:

find_real_file.png

function TestUiScripts() {
    console.log('Script called.');

    TestUiScripts.testAlert = function() {

        alert('text');

    };
}

As you can see I expect a log statement and an alert popup on click of the ui action, but nothing happens.

It seems that the ui script is not called.

Maybe I made a mistake when creating the ui script. Is there a special way to create a ui script as .jsdbx?

 

Thanks for you help and knowledge,

Dominique

4 REPLIES 4

Naveen20
ServiceNow Employee
ServiceNow Employee

You can call the ui script from a client script or UI policy. For ui action you can create a script include or add your function to an existing script include and it will work.

You can check the OOTB ui action Create Problem which calls function (getProblemFromIncident) in IncidentUtils script include.

sindhuja5
Giga Contributor

Hi,

I am working on something similar & face the same issue. I created a custom UI script and a UI action.

I tried to mimic the OOB problem button "Start Fix". But the UI action does not seems to invoke the UI script.

Out of curiosity , i even copied the "OnFix" function in "ProblemModalUIHelpers" UI script, renamed as "onFix1" in the same UI script file and then tried to invoke in my UI action. Never worked !. Latest version of the OOB UI script is not being executed even though i cleared the browser cache.

I tried to use a formatter to load the custom UI script but in spite it did not work 😞 .

Were you able to find a solution to this ?

 

Regards

Sindhuja

Hi Sindhuja,

Did you get any solution for this?

Regards,

Roshnee

Your feedback makes the community stronger! If you found this helpful, marking it as the correct answer helps others.
Stay awesome,
Roshnee Dash

sindhuja5
Giga Contributor

Finally i got this working!!

I used the below script in the UI action to load the UI script.

 

sample code:

if (g_form && g_form.mandatoryCheck()) {
ScriptLoader.getScripts("myUIscript.jsdbx", function() {
myUIscript.myfunction();
});
}

 

Note:

The browser cache needs to be cleared each time the custom UI script is being updated for it to reflect properly on the form.