- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2016 11:24 AM
I'm trying to get a UI Action to appear based on a function in a script include.
My script include contents:
function myCustomShowUIButton() {
return false;
}
The condition line of my UI action:
myCustomShowUIButton()
I would expect the UI action button to not appear because the function returns false. However this does not appear to work. Any ideas?
Jason
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-29-2016 08:49 AM
You are correct about UI actions being executed on the client side, but incorrect regarding the condition and visibility. If the condition on a UI action is not met, the html and java-script is not even sent to the browser, so the button never appears at all (not even briefly). If using a client script to hide a button, the html and javascript must first be sent to the browser, and it is displayed. Once the client scripts then catch up, the button disappears, but this can take about 1 second so the button appears briefly.
Sadly I do not think a function from a Script Include (whether a simple function or using a class) can be used on the condition line of a UI Action.
Jason
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2016 11:45 AM
1. What is your script include name? The way to call script include functions are
new <script>.<method name>(<parameters>);
Also while calling it from conditions, I have always see using javascript before the call. i.e.:
javascript: new <script>.<method name>(<parameters>);
2. Have you confirmed that your function is being called correctly. I would type a gs.log statement before return to confirm that function call is correct.
- Hardik Vora
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2016 11:52 AM
Hi Jason,
A script include shouldd have a class and then a function, you can't use it without these two elements.
Here is an article concerning script include : Script Includes - ServiceNow Wiki
Why are you using script include ti hide/show button ? it could be done easily without script include. Here is another article for a sample of script : Client & Server Code in One UI Action - ServiceNow Guru
if you really want to use a script include, here is a way to achieve what are you trying to do, you have to script something like this in your script include:
- var TestFunction = Class.create();
- TestFunction.prototype = Object.extendsObject(AbstractAjaxProcessor, {
- testingFunction: function() {
- return false
- }
- });
Then in your ui script you have to put something like that
var ga = new GlideAjax('TestFunction');
ga.addParam('sysparm_name','testingFunction');
ga.getXML(HelloWorldParse);
function HelloWorldParse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
}
let me know it that works or not, this script should return the false value, you have to add in your ui action that if the answer == 'false' then
g_form.setVisible('button name', false)
Kind regards,
ZA
Mark Helpful or correct answer depending on the impact of the answer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2016 11:53 AM
One note : here is another article which shows how to interact with script include : http://wiki.servicenow.com/index.php?title=GlideAjax#gsc.tab=0
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2016 11:58 AM
I want the button only to appear if a record appears in a different unrelated table.
I'm sure I can do it with a UI policy or a client script, I just thought the condition on a UI Action would be cleaner. Otherwise, with a ui policy or client script, it seems like the forms shows the button, and then as soon as the java-script catches up, quickly hides the button.
Jason