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

I am failing in keeping the count of the approved/rejected status in the glided table

if that is solved, it will work.

 

Appreciate your help,

Thank you.

Hi Palmen

I am checking with agg.getAggregate('COUNT') and it gives value 1 when the condition met or records with matched status found.

 

Now I want to store the count and show the button, because for everything time of new record creation the COUNT value is refreshed from 0-1 again.

 

scenario: When we hv two approved records, it shows up Approve related button, but when a new record created and rejected then it show only Reject related button and the approved button previously is not visible.. I need both buttons to be visible when we hv combination of both states.

 

hope I am clear with my requirement,

Much appreciated your help.

thank you.

Try with this script, it'll store the count value in a count variable.
Should have been in the code from the beginning but used the answer variable instead by mistake

var agg = new GlideAggregate('x_tere_telstra_who_adjustment');
agg.addQuery('sys_id',current.sys_id);
agg.addQuery('state', '5');  // here we use 13 for approve function
agg.addAggregate('COUNT','state');
agg.query();
var answer = 'false';
var count = '';
if (agg.next()) {
 count = agg.getAggregate('COUNT');
 if (count > 0)
 answer = 'true';
 else
 answer = 'false';
}
 gs.info('intonewscrptInc CANCEL'+agg.getAggregate('COUNT'));
return answer;

Did you get it to work?

Nope. in the above code

 

agg.addAggregate('COUNT','state');

is not working and I am passing the object from UI action condition block and accessing the glided object coloumns in Script Include through object.sys_id, instead of current.sys_id.

 

Thank you for the help.