Dynamic field name reference

ecarmody
ecarmody Member Posts: 53
Hello,

How can I code a reference to a field name using a string variable?

For example, I am trying to set a filter on one of two fields. Rather than coding a
IF (condition 1)
... SETFILTER("field1", condition)
ELSE
... SETFILTER("field2", condition)

I'd rather code something like
... SETFILTER('field' + position, condition)

Thanks,
Eric

Comments

  • girish.joshi
    girish.joshi Member Posts: 407
    There is no way to do this. Sorry.
  • kine
    kine Member Posts: 12,562
    1) You can user RecordRef and FieldRef to create such a function but with limitation (you will need to work wit RecordRef which is not so easy...)

    2) You can use something like GETVIEW and SETVIEW to set the filter by text. But of course, you must know what you are doing and why. In most cases the CASE or IF statement is much better...
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • girish.joshi
    girish.joshi Member Posts: 407
    You can use FieldRef's to programatically access fields and then set filters on them.

    However, you can't set "conditional" filter other than the way you described in your first post. By a conditional filter, I mean, filtering one field or filtering on a different field.