Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik GA: Multivariate Time Series in Qlik Predict: Get Details
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

GetField Example from API Guide not working

All -

Trying to get this working:

set fld=ActiveDocument.GetField(1)
msgbox(fld.Name)


What I think this is supposed to do is access the array of fields returned by the load script by index number rather than by name. What actually happens is:

error loading image

Executing the code this way proces the desired result:

sub create_chart2()
set fld = ActiveDocument.GetField("Product")
txtName = fld.Name
msgbox(txtName)
end sub


Am I off target by assuming that the Example in the API Guide for GetFiel is using an array index?

1 Solution

Accepted Solutions
Not applicable
Author

Digging around the API Guide, I found something that may work, but it's a little messier.

Sub Test
set flds = ActiveDocument.GetFieldDescriptions
for i = 0 to flds.Count - 1
set fld = flds.item(i)
if not fld.IsSystem then
txtName = fld.Name
msgbox(txtName)
end if
next
End Sub


That allows you to loop through every field. Unfortunately, that loop gets you System Fields, so I added the IsSystem check to check for those.

View solution in original post

7 Replies
Miguel_Angel_Baeyens

As far as I understand, the example may be wrong, as you can access objects in two ways. One is referencing the object by name (as you did in your code example), and the other would be:

sub create_chart2()
set fld = ActiveDocument.Fields(1)//change number/reference to get the number in the object array
txtName = fld.Name
msgbox(txtName)
end sub


Regards.

Not applicable
Author

Thanks for the response:

Unfortunately that gives me the same error:

Object required:'fld'

Not applicable
Author

EDIT: Sorry, I misunderstood your post. You want to use the field array. Please ignore. Big Smile

Try this:

sub create_chart2()
set fld = ActiveDocument.Fields("Product")
txtName = fld.Name
msgbox(txtName)
end sub


It seems there are a few ways to reference fields. There was a brief discussion in one of these threads a while back, but I don't think anyone came up with a difference.

Not applicable
Author

So if it is impossible to reference a loadscript field by array index, is there any way to dynamically create a chart that displays all fields loaded in the script?

The manual adding would be a deal breaker as it would more or less require a huge manual effort to add each field through the wizard, every time we wanted to consider a different table...

Not applicable
Author

Digging around the API Guide, I found something that may work, but it's a little messier.

Sub Test
set flds = ActiveDocument.GetFieldDescriptions
for i = 0 to flds.Count - 1
set fld = flds.item(i)
if not fld.IsSystem then
txtName = fld.Name
msgbox(txtName)
end if
next
End Sub


That allows you to loop through every field. Unfortunately, that loop gets you System Fields, so I added the IsSystem check to check for those.

Not applicable
Author

Thanks all, NMiller got it!

rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP


wytworm wrote:there any way to dynamically create a chart that displays all fields loaded in the script?


The system field '$Field" contains a row for every field present in the document. $Field can be used in a chart. Is that what you are looking for?

-Rob