show / Hide of list banner buttons based on status of related list records

nanisonline
Kilo Contributor

Hi Guys,

I have written a List banner buttons (approve/reject) to show up on related list based on related list record status.

I have written as (current.state==13) for showing up button when current record is approved and (current.state==5) when current records is rejected.

But when related list has combination of both approved and rejected records, the related list should contain both approve and reject buttons.

Please help me how to keep the COND statement for this scenario in list banner button.

Appreciate your help,

Naveen B

1 ACCEPTED SOLUTION

I do get it to work with passing the sys_id to the script include by using current.getUniqueValue()

 

Condition in UI Action

new testUtils().testFunction(current.getUniqueValue());

 

My Script Include

var testUtils = Class.create();
testUtils.prototype = {
	initialize: function() {
	},
	testFunction: function(sysid) {
		gs.log('TEST sys_id: ' + sysid);
		var agg = new GlideAggregate('incident');
		agg.addQuery('parent', sysid);
		agg.addAggregate('COUNT');
		agg.query();
		var answer = 'false';
		var count = '';
		if (agg.next()) {
			count = agg.getAggregate('COUNT');
			if (count > 0)
				answer = 'true';
			else
				answer = 'false';
		}
		gs.log('TEST count: ' + count);
		gs.log('TEST answer: ' + answer);
		return answer;
	},
	
	type: 'testUtils'
};

 

My button is being displayed/hidden depending on if there are any child incidents connected to an incident (using parent field)

Remember to check the checkbox Client Callable on the Script Include.

View solution in original post

20 REPLIES 20

Bhagyashree8
Kilo Guru

HI,

 

Why do you need Approve button if record is already approved?

 

Mark my ANSWER as CORRECT / HELPFUL if it served your purpose.

palmen
Tera Guru

You need to make a glideaggreagate query to the table for the related records and check the status.

If it contains at least one rejected and one approved you should display the button.

There are good examples on the docs about how to write a glideaggregate query
https://docs.servicenow.com/bundle/kingston-application-development/page/app-store/dev_portal/API_re...

Here is a code sample that should work 

var agg = new GlideAggregate('TABLE FOR THE RELATED LIST');
agg.addQuery('sys_id', 'SYS ID OF THE CURRENT RECORD');
agg.addQuery('state', '13');
agg.addAggregate('COUNT');
agg.query();
var answer = 'false';
if (agg.next()) {
	answer = agg.getAggregate('COUNT');
	if (answer > 0)
		answer = 'true';
	else
		answer = 'false';
}
return answer;

 

Put this as a function in a script include and call it in the condition field
new scriptIncludeName().functionName()

thank y..but I need to define visible condition on COND block.

Can we use answer == true on condition blick of UI action with executing this code in the script section.