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

Hi @Priya75,

please try below script:

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,field');
gr.groupBy('order', 'field');
gr.addHaving('COUNT', '>', 1);
gr.query();

var duplicatePolicies = [];
while (gr.next()) {
    var order = gr.getValue('order');
    var field = gr.getValue('field');

    var actionGr = new GlideRecord('sys_ui_policy_action');
    actionGr.addEncodedQuery("order=" + order + "^field=" + field + "^ui_policy.active=true^ui_policy.sys_scope=global");
    actionGr.query();

    if (actionGr.next()) {
        duplicatePolicies.push(actionGr.ui_policy.sys_id);
    }
}

if (duplicatePolicies.length > 0) {
    gs.print("Duplicate UI Policies found:");
    gs.print(duplicatePolicies.join(', '));
} else {
    gs.print("No duplicate UI Policies found.");
}

Thank you, please make helpful if you accept the solution.

SN_Learn
Kilo Patron
Kilo Patron

Hi @Priya75 ,

 

The table [sys_ui_policy_action] UI Policy action is not having 'order' field.

UI policies table[sys_ui_policy] is having that field.

 

 

 

var gaDupCheck1 = new GlideAggregate('sys_ui_policy_action');
    gaDupCheck1.addEncodedQuery("table!=NULL^ui_policy.active=true^ui_policy.sys_scope=global");
    gaDupCheck1.addAggregate('COUNT', 'field');
    gaDupCheck1.groupBy('field');
    gaDupCheck1.addHaving('COUNT', '>', 1);
    gaDupCheck1.query();
    while (gaDupCheck1.next()) {
          var dupRecords1 = gaDupCheck1.ui_policy;
    }
    gs.print(dupRecords1);

 

 

 

This will check for the same field name and print the Ui policy of it.

 

Mark this as Helpful / Accept the Solution if this helps 

----------------------------------------------------------------
Mark this as Helpful / Accept the Solution if this helps.

Priya75
Tera Contributor

Hi,

I tried but not working, can I use dot walk with orderBy.