Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get data into an Article #23

Closed
toshiro92 opened this issue Jul 29, 2016 · 9 comments
Closed

Get data into an Article #23

toshiro92 opened this issue Jul 29, 2016 · 9 comments

Comments

@toshiro92
Copy link

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
Copy link
Owner

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

@toshiro92
Copy link
Author

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
Copy link
Owner

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
Copy link
Author

Ok great ! Thank you @ewsterrenburg

@mjducharme
Copy link
Collaborator

@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
Copy link
Owner

ewsterrenburg commented Jul 29, 2016

@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.

@ewsterrenburg ewsterrenburg reopened this Jul 29, 2016
@mjducharme
Copy link
Collaborator

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
Copy link
Owner

@mjducharme in your new code, this is handled fine

@toshiro92
Copy link
Author

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'
[...]
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants