Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Something like peek(fieldname,row,table) to use in a macro

Hello,

I need to search in a table for a given value into a field and get the contents of another field in that same row.

The peek(fieldname,row,table) would be the most suitable tool to do this in the script but I need to do so in a macro (regardless execution of reloads).

Can someone help me?

1 Solution

Accepted Solutions
Not applicable
Author

Hi Carlos, as far as I know, you cannot retrieve information from a table loaded in the section access, you can only do it, with the data loaded in the section application. So taking that in to consideration, if you have your table in the application section, you could use a similar expression to the following:

=only({$<User = {'$(=qvuser())'}>} Feature)

Notice, you could change the qvuser() function, for the osuser(), depending on how you define yout section access.

Regards

View solution in original post

9 Replies
Not applicable
Author

Hi, you can use a similar code to the following within your macro to look for a specific cell value within an specific object and set a variable with this value, that you could use in some other formula:

sub GetCellAndSetVar(obj, var, x, y)

    set v = ActiveDocument.Variables(var)

    set chart = ActiveDocument.GetSheetObject(obj)

   

   

    set cell = chart.GetCell(x,y)

    cell_content = cell.Text

   

        v.SetContent cell_content,true

end sub

Perhaps, We can be more helpful if you can provide some more detail about your specific requeriment, since the use of macros are not always the best way to solve the problems, if you give us the complete picture, probably we can recommend you a way to solve your problem without macros.

Regards

stephencredmond
Luminary Alumni
Luminary Alumni

Hi Carlos,

Have you looked at the Lookup function?  Seems to me to be exactly what you want based on your description - looks up a value in a field and returns the value in another field in the same row.

Regards,


Stephen

Not applicable
Author

Stephen, lookup would be the ideal function to do this but I need to do this in a macro (not in the script).

Not applicable
Author

Hi Carlos, I once have a requirement in which I made a calculation in a chart and then I had to look for the matching calculation in other table and get the corresponding value, I solved it using an aggr function, but it will hardly depend on your particular issue, I think we can be more help if you could post and example.

Regards

Not applicable
Author

Ivan,

I need to retrieve some feature of the current user which is located in a file which I load in the Acces Section.

As the current user may change without doing a reload I can't do this in the Script.

Not applicable
Author

Stephen,

I was thinking in a macro to run a for ... next loop to look for the searched value within the table. But now I see that with lookup I can do it with an expression.

The problem now is that I can not use the lookup() function to define a variable. Why?

Not applicable
Author

Hi Carlos, as far as I know, you cannot retrieve information from a table loaded in the section access, you can only do it, with the data loaded in the section application. So taking that in to consideration, if you have your table in the application section, you could use a similar expression to the following:

=only({$<User = {'$(=qvuser())'}>} Feature)

Notice, you could change the qvuser() function, for the osuser(), depending on how you define yout section access.

Regards

Not applicable
Author

Thank you Ivan.

I reloaded the 2 interesting fields of the access table (changing the field names, of course) in the Section Application and used your sugestion:

=only({$<WINUSER = {'$(=Osuser())'}>} TIPOUSER)

It works perfect but I have to admit that I just copied what you proposed without understanding the syntax of this expression. Where can I get more information about this? (not clear enough in the reference book)

Not applicable
Author

Hi Carlos, I inivite to take a look at the following topics within the reference manual:

-Dollar sign expansion

-Set Analysis

-Only function

What we are doing basically is telling QV to retrieve the TIPOUSER where the WINUSER field is the same as the currently logged in user.

Best regards