unable to print the value in script

Priya75
Tera Contributor

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); }

 

7 REPLIES 7

Mark Roethof
Tera Patron
Tera Patron

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

LinkedIn

that was a typing mistake here , its fine in the code.

Yashsvi
Kilo Sage

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.

Priya75
Tera Contributor

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.