Built something you're proud of? Tell the story. A quick G2 review of App Engine or Build Agent helps other developers see what's possible on ServiceNow. Share your experience.

Use Case

ShraddhaM475477
Tera Contributor

If there is a custom field on click of UI action I want to populate count of incident which are from same assignment group and I want to show this field to only admin or ITIL user which modules you will use for this?

1 ACCEPTED SOLUTION

Sid_Takali
Kilo Patron

Hi @ShraddhaM475477 You can try to create a Read ACL on the count field and use below script in advanced condition

answer = gs.hasRole('admin') || gs.hasRole('itil');

View solution in original post

2 REPLIES 2

Sid_Takali
Kilo Patron

Hi @ShraddhaM475477 You can try to create a Read ACL on the count field and use below script in advanced condition

answer = gs.hasRole('admin') || gs.hasRole('itil');

souravpradh
Tera Contributor

create a Client UI Action that calls a Server-side Script Include to fetch the count. Use a Read ACL to restrict field visibility and a UI Policy to hide it on the form.

 

Client UI Action:

Condition:

gs.hasRole('admin') || gs.hasRole('itil');

 

function calculateIncidents() {
var group = g_form.getValue('assignment_group');
if (!group) {
alert('Please select an Assignment Group first.');
return;
}

// GlideAjax to get count from server
var ga = new GlideAjax('IncidentCountAjax');
ga.addParam('sysparm_name', 'getSameGroupCount');
ga.addParam('sysparm_group', group);
ga.getXMLAnswer(function(answer) {
g_form.setValue('u_same_group_count', answer);
});
}

 

Script Include:

 

var IncidentCountAjax = Class.create();
IncidentCountAjax.prototype = Object.extendsObject(AbstractScriptInclude, {
getSameGroupCount: function() {
var group = this.getParameter('sysparm_group');
var count = 0;
var gr = new GlideRecord('incident');
gr.addQuery('assignment_group', group);
gr.addQuery('active', true); // Optional: Count only active
gr.query();
return gr.getRowCount();
},
type: 'IncidentCountAjax'
});