Forum Discussion

varun_masuraha's avatar
varun_masuraha
Contributor
3 years ago

How to find object(s) with conditions on numeric properties, like “>x”, “<x”, “not 0", etc. ?

Hi,

Consider a script example: 

>>> results = myObject.FindAll( ["contentText", "ChildCount"], ["Employer", << greater than 5 >>] );

How to implement the red part in above query, where we're interested in finding all objects with certain contentText & ChildCount>5, or any such numeric conditions ?

 

I'm using TC v15.40.421.7

 

Thanks.

  • Hi,

     

    Technically, something like this (untested regex) should work:

    results = myObject.FindAll( ["contentText", "ChildCount"], ["Employer", "regexp:^([6-9])|(\\d{2,})$"] );

    where ([6-9])|(\\d{2,}) regex means: either a figure in a range from 6 to 9 or any combination of two or more figures.

    However I am not sure that this approach is easily parameterizable (for the case when today you are looking for child count greater than 5, but tomorrow you will need to search for 7 or more children).

    So I, probably, would just search for all "Employer"s and then loop through the returned array and remove those elements that do not fit your condition.

     

  • AlexKaras's avatar
    AlexKaras
    Champion Level 3

    Hi,

     

    Technically, something like this (untested regex) should work:

    results = myObject.FindAll( ["contentText", "ChildCount"], ["Employer", "regexp:^([6-9])|(\\d{2,})$"] );

    where ([6-9])|(\\d{2,}) regex means: either a figure in a range from 6 to 9 or any combination of two or more figures.

    However I am not sure that this approach is easily parameterizable (for the case when today you are looking for child count greater than 5, but tomorrow you will need to search for 7 or more children).

    So I, probably, would just search for all "Employer"s and then loop through the returned array and remove those elements that do not fit your condition.