Search code examples
python-3.xworkfront-api

How to retrieve Custom Field values in Workfront via Python?


How do you read custom field values that are returned to a variable? In the example belpw, if I had a custom field in a project called "Custom Field" I understand I can search and return it by saying:

results = client.search(ObjCode.PROJECT,{'groupID':user.homeGroupID},fields=['DE:Custom Field'])

How would I the read the value of the custom field that has spaces in the name? similar to:

print(results.status)

How would you do something similar for a custom field like:

print('results.CustomField')

Solution

  • If the call runs successfully, the value of results should now be a JSON object. That JSON object should have several default fields such as ID and possibly name, but it will also have a field named DE:Custom Field and the value. For example:

    {'ID':'ABC123F2010314AFE1...', 'DE:Custom Field': 'This is the value of my custom field'}

    So in python you would get the value using square bracket notation (assuming you have converted from JSON to a python object). In this case

    print(results['DE:Custom Field'])