4 Replies Latest reply on Feb 16, 2017 10:01 PM by arjen.evertse

    Problems with GetFieldName function

    deanchampeau

      Hi everyone,

       

      I've known about the GetFieldName function for some time but was always too intimidated to put it to use. Now I need it because I'm building a script that moves among several fields and sniffs them to determine if there are any instances of two carriage returns. Here's the sniffer code...

       

      PatternCount ( GetFieldName(Evaluate(Get(ActiveFieldName))) ; "¶¶" )

       

      No matter what's in my field, my code always returns 0 for the pattern count. If I simplify the code replacing GetFieldName(Evaluate(Get(ActiveFieldName))) with the actual field, then the PatternCount function works as expected.

       

      Any of you wizards got a clue what I'm doing wrong?

       

      Thanks,

      Dean

        • 1. Re: Problems with GetFieldName function
          philmodjunk

          GetFieldName expects the fields internal ID as its parameter. Your expression does not return that value.

           

          I would use get ( activeFieldContents )

           

          here.

           

          Also note that if the field had two returns but with one or more other characters between them, your use of patterncount will return zero.

          • 2. Re: Problems with GetFieldName function
            deanchampeau

            I see what you did there. By using get (activeFieldContents) I'm checking for my two carriage returns by searching the actual text instead of trying to refer to a field name.

             

            I did discover on my own that by removing the GetFieldName function from the code...

             

            PatternCount ( Evaluate(Get(ActiveFieldName)) ; "¶¶" )

             

            ... it works great.

             

            Correct me if I'm wrong, but I think my error was using the GetFieldName function in the first place, because it turns what was Evaluated back into text, which then PatternCount cannot evaluate properly. By using just Evaluate around Get(ActiveFieldName), I'm doing what you say above, i.e. converting the text into the internal field ID. Do I understand this correctly? If so, I think I finally grok the Evaluate function fully for the first time.

            • 3. Re: Problems with GetFieldName function
              user19752

              If you use Get(ActiveFieldName), there is no advantage than get ( activeFieldContents ) that phil mentioned.

              If you try to get field contents from various field names without activating the field, you need Evaluate() like

              Evaluate($fieldName)

              1 of 1 people found this helpful
              • 4. Re: Problems with GetFieldName function
                arjen.evertse

                Functions and field references are always evaluated when used inside a calculation. Evaluate is a function that will evaluate the text supplied as parameter as if it was a function, formula or field reference.

                 

                Think about out it as you have a text field where you type the formula: 1 + 1. Referencing the field in any calculation would return the text 1+1 into your calculation but if you would use Evalute ( table::textfield ) it would evaluate the formula before evaluating the rest of the calculation.

                 

                Say would like to add 2 to the result of  formula in your text field:

                 

                table::field + 2 would return 13

                Evaluate ( table::field ) + 2 would return 4

                 

                In this case FM will take only the numbers in your text field '11' and add 2 which makes 13 but in other scenarios you will likely get a more unexpected result or ?.