Jump to content

Recommended Posts

Posted

Hi,

I'm struggling with getting and setting custom attribute value for task, which type is a link to a user.

Example:

I have a shot that consists of 8 tasks. For every task I have Assignee and I created custom attribute (reviewer) as on screen below.

image.thumb.png.42af8a9b036a5bcdf4fdc72568fc827f.png

Now I want to create two lists containing: all artists assigned to any task in this shot, and the same with reviewers.

While getting assignees is quite straightforward, getting custom attribute link is the whole different story.

Obviously I cannot do something like task['custom_attribute']['reviewer'], which would be awesome...

So could you please help me out here and give some advice how to approach this problem?

 

 

Posted

Hi @Lorenzo Angeli. Thank you for quick response :) Yep I saw documentation but was hoping to get this data in more indirect way  ;)

I've managed to get usernames this way:

reviewers_ids = []
reviewers_result = ftrack.query(
    'select to_id from CustomAttributeLink where '
    'configuration.key = "reviewer" and from_id in ({})'.format(', '.join(tasks_ids))
)
for i in reviewers_result:
    reviewers_ids.append(i['to_id'])
users = ftrack.query('User where id in ({})'.format(', '.join(reviewers_ids)))
for user in users:
    print(user['username'])

Could you please verify if this is the right approach and most effective one?

Maybe I could somehome merge all those querries into one to increase performance?

 

  • 2 weeks later...
Posted

Assuming you are working with an API that supports tasks and custom attributes (such as Shotgun or a similar project management tool), here are some steps to follow:

1. Understanding the API Structure
2. Fetching Task Data

3. Extracting Custom Attribute Links

4. Setting Custom Attribute Links

5. Handling Edge Cases

Example Implementation
Here’s a more complete example putting all the steps together:

import requests

# Configuration

api_base_url = "https://api.example.com"

headers = {

  "Authorization": "Bearer YOUR_API_TOKEN",

  "Content-Type": "application/json"

}

# Helper function to fetch user details

def fetch_user(user_link):

  response = requests.get(f"{api_base_url}/users/{user_link}", headers=headers)

  return response.json()

# Fetch tasks

tasks_response = requests.get(f"{api_base_url}/tasks", headers=headers)

tasks = tasks_response.json()

artists = []

reviewers = []

for task in tasks:

  custom_attributes = task.get("custom_attributes", {})

  artist_link = custom_attributes.get("artist_link")

  reviewer_link = custom_attributes.get("reviewer_link")

   

  if artist_link:

    artists.append(fetch_user(artist_link))

   

  if reviewer_link:

    reviewers.append(fetch_user(reviewer_link))

# Output the lists

print("Artists:", artists)

print("Reviewers:", reviewers)

# Example of updating a task

task_id = "12345" # Example task ID

update_payload = {

  "custom_attributes": {

    "artist_link": "new_artist_link",

    "reviewer_link": "new_reviewer_link"

  }

}

update_response = requests.put(f"{api_base_url}/tasks/{task_id}", headers=headers, json=update_payload)

if update_response.status_code == 200:

  print("Task updated successfully")

else:

  print("Failed to update task:", update_response.content)

Adjust the field names, endpoint URLs, and request structure according to the specific API https://tech-stack.com/blog/what-is-an-api/ you are using. This should give you a good starting point to manage custom attribute links for tasks effectively.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...