unable to print the value in script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2024 11:14 PM - edited 07-09-2024 11:15 PM
Hi All,
I am trying to find the UI policies where the order and the UI policy action is same, I have written a background script, but it is not printing the values.
var gr = new GlideAggregate('sys_ui_policy_action');
gr.addEncodedQuery("table!=NULL^ui_policy.active=true^ui_policy.sys_scope=global"); gr.addAggregate('COUNT','field'); gr.groupBy('order'); gr.addHaving('COUNT','>',1); gr.query(); while(gr.next()){ var policySysID=gr.getValue("ui_policy");
gs.print(policySysID); }

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2024 11:17 PM
Hi there,
Haven't verified the scripting itself, though already the line with gs.print is incorrect:
gs.print(policy);
policy is nothing, its now out of the blue appearing in your script? You didn't declare it anywhere, didn't set is anywhere, etc.. So at least this already never works.
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2024 11:19 PM
that was a typing mistake here , its fine in the code.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2024 11:34 PM
Hi @Priya75,
please try below code:
var gr = new GlideAggregate('sys_ui_policy_action');
gr.addEncodedQuery("table!=NULL^ui_policy.active=true^ui_policy.sys_scope=global");
gr.addAggregate('COUNT', 'order');
gr.groupBy('order');
gr.query();
var duplicateOrders = [];
while (gr.next()) {
if (gr.getAggregate('COUNT', 'order') > 1) {
duplicateOrders.push(gr.getValue('order'));
}
}
if (duplicateOrders.length > 0) {
var actionGr = new GlideRecord('sys_ui_policy_action');
actionGr.addEncodedQuery("orderIN" + duplicateOrders.join(',') + "^ui_policy.active=true^ui_policy.sys_scope=global");
actionGr.query();
while (actionGr.next()) {
gs.print("UI Policy: " + actionGr.getValue('ui_policy') + " | Order: " + actionGr.getValue('order'));
}
} else {
gs.print("No duplicate orders found.");
}
Thank you, please make helpful if you accept the solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2024 11:39 PM - edited 07-09-2024 11:40 PM
I want to check the order and the field(Ui policy action field) both, if order is same and field is also same then get the UI policy (sys_id) of the policy.