- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-27-2015 03:20 PM
I have a UI Action that should pop up a UI page on click. Instead it is redirecting to the previous page. There is an error in the console saying that securityQuestions() is not defined but I'm unsure where it should go as it is already listed in the script section. I tried checking the client box and including an OnClick for securityQuestions() but that redirected to the previous page as well with the same error. I'm sure I am doing something wrong but can't seem to find what it is. The UI Action code is below and I can post the UI Page code if it is necessary.
/* UI Action Name = Security Questions Table = Incident Order = 100 Action name = Active = true Show insert = false Show update = true Client = false Form button = true Form context menu = true Form link = false List banner button = false List bottom button = false List choice = false List link = false */ /* Comments = Hint = //change to a to-be-created security role Conditions = g_user.isMemberOf('groupName') */ //Script = function securityQuestions() { if (g_user.isMemberOf('groupName')) { var questionArray = getQuestions(); var dialog = new GlideDialogWindow("dac_security_questions"); dialog.setTitle("Security Questions"); dialog.setPreference("questionArray", questionArray); dialog.render(); }; else { alert('You do not have sufficient permission to proceed with this request. Please contact your supervisor to get the necessary approval') }; }; function getQuestions() { var target = new GlideRecord('u_dac_security_questions'); var caller = current.u_caller_name; var questionArray = []; target.addQuery('u_caller_name', caller); target.query(); while (target.next()) { var tempArray = []; tempArray.push(g_form.getValue('u_question')) tempArray.push(g_form.getValue('u_answer')) questionArray.push(tempArray) }; return questionArray; };
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-28-2015 09:37 AM
function securityQuestions() {
if (1) {//you could use g_user.hasRole()
var questionArray = getQuestions();
var dialog = new GlideDialogWindow("dac_security_questions");
dialog.setTitle("Security Questions");
dialog.setPreference("questionArray", questionArray);
dialog.render();
}
else {
alert('You do not have sufficient permission to proceed with this request. Please contact your supervisor to get the necessary approval');
}
}
function getQuestions() {
var questionArr = [1,2,3,4];
return Object.toJSON(questionArr);//enconding array ( which is infact a JSON to string to pass it over to Server Side).
}
Works fine for me. This is a leaned down version, but if you can paste the UI page, I will modify everything properly and paste it for you.
Also there are couple of additional things that need discussion.
Demo instanceTested : ServiceNow
UI Action : Sample ( on Incident Table)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-27-2015 03:50 PM
Some things need change. You are using Client Object with a server function etc., Couple of things :
1. g_user.isMemberOf('groupName') - There is no function called isMemberOf .. It belongs to `gs` which is a server side object.
2. You MUST click Client and have the statement `securityQuestions()` in the onClick because GlideDialogWindow is a client side Object.
3. You shouldn't be using `GlideDialogWindow` inside a Server script.
Along will all of this, I'm not sure if you need to end if () {}; with a semi colon. Usually we end If with a semi colon only if there is a single statement. When I tried this on my instance, it will erroring out. I'm not sure why. So you might want to just use if and else with no semi colons at the end.
javascript - Why is it that semicolons are not used after if/else statements? - Stack Overflow
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-28-2015 08:01 AM
I swapped isMemberOf for hasRole, checked client and put in securityQuestions() as the onClick, and removed the ; from the if else. Now it doesn't redirect to the prior page it just comes up with an error saying that securityQuestions is not defined.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-28-2015 09:37 AM
function securityQuestions() {
if (1) {//you could use g_user.hasRole()
var questionArray = getQuestions();
var dialog = new GlideDialogWindow("dac_security_questions");
dialog.setTitle("Security Questions");
dialog.setPreference("questionArray", questionArray);
dialog.render();
}
else {
alert('You do not have sufficient permission to proceed with this request. Please contact your supervisor to get the necessary approval');
}
}
function getQuestions() {
var questionArr = [1,2,3,4];
return Object.toJSON(questionArr);//enconding array ( which is infact a JSON to string to pass it over to Server Side).
}
Works fine for me. This is a leaned down version, but if you can paste the UI page, I will modify everything properly and paste it for you.
Also there are couple of additional things that need discussion.
Demo instanceTested : ServiceNow
UI Action : Sample ( on Incident Table)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-28-2015 10:32 AM
I'm not sure what the problem was but it does work now. Thank you for the help!