Delete carriers

	instances = self.view.params.carrierListInstances
	num = sum(instance['remove'] for instance in instances)
	
	if num > 1:
	    for instance in instances:
	        instance["remove"] = False
	        system.perspective.print(instances)
	else:
	    instances = [instance for instance in instances if not instance['remove']]
	
	self.view.params.carrierListInstances = instances


please help what is wrong in my code when the instances with 'remove': True is greater than 1 i want output that all instances with remove become false.

I'm not quite sure what you want to do.
Try this in Script Console and see if you can spot your problem.

instances = [
	{"val": 0, "remove": False},
	{"val": 1, "remove": False},	
	{"val": 2, "remove": True},	
	{"val": 3, "remove": True},	
	{"val": 4, "remove": False}
]

print instances

num = sum(instance['remove'] for instance in instances)
print num
if num > 1:
    for instance in instances:
        instance["remove"] = False
        print(instance)
else:
    instances = [instance for instance in instances if not instance['remove']]

print instances

Change the number of "True" instances to test.

thankyou i will try


in script console it works

but when i use it not work

Sorry, not enough information to help you.

Any errors in the gateway logging page? That is where errors in perspective will show up.

What exactly are you trying to do? That will help us understand how to interpret your code properly.

This looks like you're trying to determine which objects to use as instances based on a param. I'd recommend binding the instances prop against that param, then assuming you just need to remove instances where this "remove" value is True, you could do this:

return [instance for instance in value if not instance["remove"]]
2 Likes

its okay my code is okay is all about indentation thankyou so much