Service Portal UI Script

Ken83
Mega Guru

Hello Community,

        I've seen this question asked before and i've seen a few others similar to it. I'm trying to configure a UI Script in my Service Portal and i'm not having any luck getting it to behave as expected. I have gone into the Theme for my Portal and added a JS Include, selected my UI Script. When I call the method from the UI Script in an onLoad Client Script, nothing happens and the following message is logged to my browser console → js_includes_sp.jsx?v=05-19-2017_1034&lp=Thu_Jun_08_10_56_47_PDT_2017&c=19_473:63723 (g_env) [SCRIPT:EXEC] Error while running Client Script "Format Work Number(Default UI)": ReferenceError: helloWorld is not defined â†� It may be worth noting that in the default UI, I get the expected result but in the Service Portal, I do not.

This is the article I was referencing →UI Script not working in new Service Portal and I noticed b-rad mention that UI Scripts may not be supported in the Service Portal. So i'm a little confused on the direction to go here. Here is the code in my UI Script which is marked active and global...

function helloWorld(){

alert("THIS IS FROM THE UI SCRIPT");

}

Any suggestions here? Am I missing something?

11 REPLIES 11

Good idea but it still did not yield any results. I'm still getting the error about the script execution in Chrome, and nothing is happening in the other browsers. This is very strange behavior.


Can you share your script along with the context that you are trying to achieve so we all can contribute.


The script is in my original post. The only other part is the onLoad client script which isn't much to see but, here it is..



function onLoad() {


    //Type appropriate comment here, and begin script below


    helloWorld();


}


lakshminarayan4
ServiceNow Employee
ServiceNow Employee

Hi ,


Actually you can use UI scripts in Service portal. it is a indirect process.   Please follow the steps.



1. Create UI script.



2. goto -> Service Portal -> Dependency-> New


        1. check "include page on load"


          2. select the page to load


         


3. add the JS Includes -> new


          1 . add the UI script.



4. Go to the widget   which is included in your page.


      1. go to the related list " Dependencies"


      2. click "Edit"


      3. Add the JS includes added in step 3.



That is it. your UI script is loaded into the page.



Please Hit ✅Correct, ��Helpful, or ��Like depending on the impact of the response



Thanks


- YLN


Thanks for the post. Very helpful.



Now that we are able to include our UI Scripts, which I don't think is the most straight forward implementation, but we can now do it.



What about the use of concepts such as Class.create()? We use classes in our UI Scripts but when imported into the Portal, we get errors stating that "Class is not defined".