Jump to content

Querying filtered tasks


HYP_STGR

Recommended Posts

I'm writing an action script that get as input all tasks whose parent(Asset Build) have a specific value in a custom attribute. Ideally, the right value of the custom attribute would be found in the Filter button/option from the site. The first problem is that i want to be able to query all tasks that have the right filter value using the API's expression language.

Something like this:

filtered_value = ??? #somehow get the filter from the site 
list_of_tasks = session.query('Task where parent.custom_attributes.my_custom_attr is {0}'.format(filtered_value)).all()

The second problem is that the custom attribute is actually a list so in the query expression i need to be able to do something like this:

list_of_filtered_values = ??? #somehow get the filters from the site
for value in list_of_filtered_values:
	#get all tasks that have the value in the custom attribute list.
	list_of_tasks = session.query('Task where {0} in parent.custom_attributes.my_custom_attr'.format(value)).all()
	#Do stuff

As of right now i'm having to query all task from the project and check which ones have the right value(i get the value from the task where the action was triggered) and then apply my action with it. It's a very inefficient approach since the project has lots of tasks(and it will have more in the future) and Python is not very fast at looping around huge lists. My code right now looks like this:

right_value = entity.get("my_custom_attr")
tasks = session.query('Task where parent.object_type.name is "Asset Build" and project.name is "my_project"').all()
for task in tasks:
	
    if episode not in task["parent"]["custom_attributes"]['my_custom_attr']:
    	continue
    else:
        #do_stuff

Is there a better solution?

Thanks!

Link to comment
Share on other sites

Quote

I'm writing an action script that get as input all tasks whose parent(Asset Build) have a specific value in a custom attribute. 

So am I right in assuming that you want to run the action on all asset builds that matches a filter criteria (in your case a custom attribute)? If so it may be easier to just do the filtering in the Spreadsheet and then multi-select => right click => Actions.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...