How to access custom attributes via javascript api?
1 1

11 posts in this topic

Hey there, 


we're currently trying to create a widget, that will list up some of our custom attributes, but for now its a struggle to get these. Maybe we just didn't look in the right place? With the python api its possible to get these values via the project: 



but with the javascript api, project don't seem to have these properties:'all project properties: ');
for(var key in currentProject)
{'project['+key+'] = ' + currentProject[key]);

gives us something like this:

all project properties: 
index.js:62 project[context_type] = show
index.js:62 project[__entity_type__] = Project
index.js:62 project[id] = 19e2f1e4-01dd-11e8-ac42-7ab7a47c9dda
index.js:62 project[name] = tims_test_321345

So if we cannot get the 'custom_attributes' via the project, where do we get them from?



thanks an advance





Share this post

Link to post
Share on other sites

Hi Tim,

In the javascript API, only attributes which you have selected using a projection will currently be available on the returned objects. In order to see what attributes are available, you need to look at the API schema (Session.schemas). Here is an example that does this using the Python API.

Here is an example of how it can be used.

/** Get custom attribute value for *entity* and *key*. */
function getCustomAttributeValue(entity, key) {
    const customAttribute = entity.custom_attributes.find(
        attribute => attribute.key === key
    if (!customAttribute) {
        console.log('Unable to find attribute', key);
        return null;
    return customAttribute.value;

// Query custom attributes for a single Shot and print the fstart custom attribute value.
    'select custom_attributes from Shot limit 1'
).then(function (response) {
      'Custom attribute value:',
      getCustomAttributeValue([0], 'fstart')



Share this post

Link to post
Share on other sites

Hey again, 


now this is what I have tried. Sadly nothing worked out so far :( 

(having an example, that does something similar, but in python, didn't help me -- maybe I didn't understand your answer?)


I tested getting the entity (btw. is there somewhere a documentation, that tells, what entity this is? By checking its name I got, that it might be the current project):

var entity = ftrackWidget.getEntity();

But the result of getting custom_attributes is undefined:

var customs = entity.custom_attributes;


In your example you do this on line 3:


What entity do I have to use for this? How do I get it? And is this even possible in javascript?

In your example you used a 'Shot' as basis to get the custom attributes from it. In our project we have project-wide custom attributes, so using a Shot/Sequence or any asset won't work for us. 


And there is more:

You wrote I should ' look at the API schema '. In the javascript api the session has a method called 'getSchema', but how am I supposed to use that? Is this even what you where talking about? 



thanks again in advance!

Share this post

Link to post
Share on other sites

Ah, I misunderstood the question somewhat. ftrackWidget.getEntity() will return an object as provided by the ftrack.wiget.update event. This reflects the currently selected entity in the project outliner to the left in the interface. The format is:

    id: 'eb16970c-5fc6-11e2-bb9a-f23c91df25eb',
    type: 'TypedContext'

In order to get get an object which contains the custom attributes, you will need to use the id and type and query the API for information you are interested in.

You can see an example of how this is done in ftrack-spark-base in ExampleContainer::onFtrackWidgetUpdate, which gets the name and link attributes. Here is where you would use the code in my last post to get the custom attribute value for the selected entity.


Share this post

Link to post
Share on other sites



now its working! Thanks again, that helped me alot. 


The only thing thats left open, is a strange warning I get for each attribute, thats inside 'custom_attributes': 

Key could not be determined for:  
	entity_id: "19e2f1e4-01dd-11e8-ac42-7ab7a47c9dda", 
	value: "*(Software version and plugins)*", 
	__entity_type__: "ContextCustomAttributeValue", 
	configuration_id: "0cec668e-e3d6-11e7-90fc-7ab7a47c9dda", 
	key: "Briefing_Workflows_06_Grading", …}

		config: "{"markdown": true}"
		core: false
		entity_type: "show"
		group_id: "5f457ef8-e3d5-11e7-93c6-7ab7a47c9dda"
		id: "0cec668e-e3d6-11e7-90fc-7ab7a47c9dda"
		is_hierarchical: false
		key: "Briefing_Workflows_06_Grading"
		label: "Grading"
		object_type_id: null
		project_id: null
		sort: 95
		type_id: "6268aef0-381c-11e0-acff-0019bb49847a"
		__entity_type__: "CustomAttributeConfiguration"
		__proto__: Object
		configuration_id: "0cec668e-e3d6-11e7-90fc-7ab7a47c9dda"
		entity_id: "19e2f1e4-01dd-11e8-ac42-7ab7a47c9dda"
		key: "Briefing_Workflows_06_Grading"
		value: "*(Software version and plugins)*"
		__entity_type__: "ContextCustomAttributeValue"
		__proto__: Object

Besides this, everything seems to be working as expected. May be this gets solved along the path of completing the whole widget..





Share this post

Link to post
Share on other sites



back on this topic and tried to get the now api version you suggested. The given link directs to '' which gives me this:


This XML file does not appear to have any style information associated with it. The document tree is shown below.
<Message>Access Denied</Message>

Could you provide another link?






Share this post

Link to post
Share on other sites

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
1 1