ewsterrenburg / python-otrs

Pythonic interface to OTRS SOAP API
GNU General Public License v3.0
47 stars 27 forks source link

Get data into an Article #23

Closed toshiro92 closed 8 years ago

toshiro92 commented 8 years ago

Hello !

I tried to extract data from an Article object following the README file, but it seems the dynamicfields function into it does not working:

File "/home/users/me/projects/virtualenv/lib/python2.7/site-packages/otrs/objects.py", line 23, in getattr return autocast(self.attrs[k]) KeyError: 'dynamicfields'

I did the following lines:

for el in ticket.articles():
   print(el.dynamicfields())

However, I showed the entire Article Object and studied it, and this is working by doing this:

for el in ticket.articles():
   print(el.attrs['CustomerUserID'])
   print(el.attrs['Subject'])
   print(el.attrs['Body'])
ewsterrenburg commented 8 years ago

@toshiro92 The dynamic fields are a property of the OTRS ticket. An OTRS article does not have dynamic fields.

toshiro92 commented 8 years ago

Hum ok, so the way to extract information from Article is to do like I wrote:

for el in ticket.articles():
   print(el.attrs['CustomerUserID'])
   print(el.attrs['Subject'])
   print(el.attrs['Body'])

Or is there a better way about ?

ewsterrenburg commented 8 years ago

You could do it like you are doing. You can also access the attributes directly, like this:

for el in ticket.articles():
   print(el.CustomerUserID)
   print(el.Subject)
   print(el.Body)
toshiro92 commented 8 years ago

Ok great ! Thank you @ewsterrenburg

mjducharme commented 8 years ago

@ewsterrenburg

Articles can have dynamic fields as well. I do not use them myself but when creating dynamic fields there are options to create them for either tickets or articles

ewsterrenburg commented 8 years ago

@mjducharme @toshiro92 I stand corrected here, never used them either and falsely assumed they were only available for tickets. Guess it would be best if dynamic fields for both tickets, articles, faq's, ... are handled the same way the articles are treated for a ticket (i.e. give back a list of DynamicFields if any, an empty list otherwise).

Reopening this issue.

mjducharme commented 8 years ago

I use dynamicfields for tickets, but not for articles. When I coded the function, I tested it only with ticket dynamic fields, and I use it with that in production; I assumed it would work for article dynamicfields as well.

ewsterrenburg commented 8 years ago

@mjducharme in your new code, this is handled fine

toshiro92 commented 8 years ago

FYI: About the DynamicFields into an Article, on my side I can see that they are named as below into an Article:

attrs = {
'Title' : 'A title',
'DynamicField_Element1' : 'An element',
'DynamicField_Element2' : 'Another element'
[...]
}