Report: SETFILTER on a option field

mgerhartz
mgerhartz Member Posts: 50
Hi,

I've got the following problem: I want to enable the user to set a filter in the request form. For example, the field I want to filter is an option field. The user enters a content like blue, green, yellow or what ever, and the SETFILTER function should compare the content of the request form field with the content of the option field. If it match, the filter has to work otherwise it has to show an error, like "unknown content, please retry". I know how the SETFILTER function works. But I have no idea, how it works with an option field. Do I have to write code for every possible option?

Thanks a lot for your help!

Markus

Comments

  • mgerhartz
    mgerhartz Member Posts: 50
    Maybee something like this?


    IF Vertragsfilter <> '' THEN BEGIN
    CASE "Workflow Vorlage".Vertragslage OF
    "Workflow Vorlage".Vertragslage::Buchungsvertrag:BEGIN
    "Workflow Vorlage".SETFILTER("Workflow
    Vorlage".Vertragslage,Vertragsfilter);
    END;
    IF "Workflow Vorlage".FIND('-') THEN BEGIN
    ELSE
    ERROR('Ungültige Option');
    END;

    and so on....

    Do I have to write code for every possible option? And there is still an syntax error. Please help :-k
  • m.gretener
    m.gretener Member Posts: 13
    Dear mgerhartz,

    you will first have to define the possible options, which the user can select from.

    Within the report create a global variable, data type Option. Then select the properties of it. In the OptionString you can enter the possible options seperated by a , (komma). After this you can program what the report should do with the selected option.

    If you define the options in the table, you can filter the option, without additional programming.

    kind regards.
  • kriki
    kriki Member, Moderator Posts: 9,133
    If you want that the user only selects 1 option it is easy.
    Create a global (e.g. optMyOptionField) that is an option and has the same options as your field.

    To test it:
    recMyRecord.RESET;
    recMyRecord.SETCURRENTKEY("My Option Field");
    recMyRecord.SETRANGE("My Option Field",optMyOptionField);
    IF NOT recMyRecord.FINDFIRST THEN
      ERROR('Not valid');
    

    Some remarks:
    1) SETRANGE can be faster then SETFILTER
    2) SETCURRENTKEY if you have a key on that field and will be a lot faster then a key on another field
    3) FINDFIRST for 4.0SP1 and FIND('-') for older versions
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • mgerhartz
    mgerhartz Member Posts: 50
    Hey Guys,

    thank you so much for your help. I will try it and let you know if it works.

    Byby

    Markus
  • mgerhartz
    mgerhartz Member Posts: 50
    Hey Guys,

    I solved my problem in a total differend way. I've created a varible with the type of option. Then I wrote in the section:

    IF Vertragsart = WF.Vertragslage THEN BEGIN
    CurrReport.SHOWOUTPUT((Structure."Organization Type"=Structure."Organization Type"::State) AND (firstsection = FALSE));
    END ELSE BEGIN
    CurrReport.SHOWOUTPUT(FALSE);
    END;

    It works fine. Thanks again to the Guys who gave me reply to my question.

    Have a nice day :wink:
  • DenSter
    DenSter Member Posts: 8,307
    You can use an option field/variable in SETRANGE like this:
    MyRec.SETFILTER(MyOptionField,'=%1',MyOptionField::Value);
    
    For some reason SETFILTER doesn't know how to interpret optionstrings directly, but by using the % notation it should work.
  • kriki
    kriki Member, Moderator Posts: 9,133
    DenSter wrote:
    You can use an option field/variable in SETRANGE like this:
    MyRec.SETFILTER(MyOptionField,'=%1',MyOptionField::Value);
    
    For some reason SETFILTER doesn't know how to interpret optionstrings directly, but by using the % notation it should work.
    Or better:
    MyRec.SETRANGE(MyOptionField,MyOptionField::Value);
    
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • DenSter
    DenSter Member Posts: 8,307
    You said that before, but I am still not convinced that it is any faster.
  • kriki
    kriki Member, Moderator Posts: 9,133
    Not always, but it is NEVER slower, and it has the potential to be faster.
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • ara3n
    ara3n Member Posts: 9,258
    I've also heard that setrange is faster in certain times and my rule is that to use setrange always, unless it's a complicated filter, and then use setfilter in those circumstances
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • kriki
    kriki Member, Moderator Posts: 9,133
    ara3n wrote:
    I've also heard that setrange is faster in certain times and my rule is that to use setrange always, unless it's a complicated filter, and then use setfilter in those circumstances
    Exactly what I do!
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!