What is wrong with my ui action code? Triyng glideform on ui action.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-30-2025 04:57 AM
Hello everyone! I'm having a problem when trying to add a gliderecord to my UI action.
I've never done this before, where am I going wrong?
Basically, I need a query to be made on the records in a related table when I click on the approve button. If there are open records related to the same, an error message appears and it doesn't approve (all of this in the workspace).
I've also tried to add the codes to the other field (script), but it didn't work.
I tried some answers through gpt, but without success.
---------------------------------
UI ACTION:
SCRIPT field:
Workspace Client Script Field:
SCRIPT INCLUDE:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-30-2025 05:42 AM
Hi Luiz,
The main issue seems to be in your script include...with the formatting of the query. This seems to be the problem:
gr.addEncodedQuery("activated_plan.event=" + eventId + "^stateNOT IN9,3,4,7");
May be better like:
gr.addEncodedQuery("activated_plan.event=" + eventId + "^state NOT IN 9,3,4,7");
Or do the GlideRecord like:
var gr = new GlideRecord('sn_recovery_event_task');
gr.addQuery('activated_plan.event', eventId);
gr.addQuery('state', 'NOT IN', '9,3,4,7');
Hope that helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-30-2025 05:58 AM
what debugging did you do?
Changes to workspace client script
1) use g_form.submit('yourActionNameHere')
Changes to script include
var CheckOpenTasks = Class.create();
CheckOpenTasks.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
hasOpenTasks: function() {
var eventId = this.getParameter('sysparm_event_id');
var gr = new GlideRecord('sn_recovery_event_task');
gr.addEncodedQuery("activated_plan.event=" + eventId + "^stateNOT IN9,3,4,7");
gr.setLimit(1);
gr.query();
if (gr.hasNext()) {
return "true"; // <- Retorne string, não booleano
}
return "false"; // <- Sempre retorne algo
},
type: 'CheckOpenTasks'
});
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-30-2025 09:46 AM
Hello, Ankur! Thanks for your reply!
Im trying putting some message logs to validate some lines, but none works as expected.
I believe I must be making a mistake when inserting the code in the script field or workspace client script.
If I make a simple code, it works normally. Is it possible to call a gliderecord through the ui action?