8 Replies Latest reply on Mar 5, 2016 12:08 AM by sfpx

    Evaluate function in Custom function

    sfpx

      I have a bunch of fields that get an image by evaluating some conditions stored in a related table.

      Without entering into details I have, in each field, a case statement.

      Something like that

      Case

      (

      Evaluate(GetValue(conditions;1);[Ofield])=1; GetValue(c;2);

      Evaluate(GetValue(conditions;3);[Ofield])=1; GetValue(c;4);

      etc...

       

      It all works well but I would like to move the case statement inside a custom function.

      I would then replace the case statement in my field calculation by  EvalCondition(conditions;ofield)

       

      The problem is that I can not specify anything as the optional field for the evaluate function inside the custom function.

      I always get the error "A number, text constant, field name or "(" is expected here".

       

      Without the optional parameter , it works but I need that optional field.

       

      So is it possible ?

        • 1. Re: Evaluate function in Custom function
          keywords

          See the following screenshot. Note that parameters are placeholders. In the definition you merely name the parameters in the middle panel and include them as is in the calculation you define in the third panel:

          Screen Shot 2016-03-05 at 8.30.51 am.png

          When the CF is deployed, this placeholders need to be substituted with actual field names, just as you do when deploying any calculation.

          • 2. Re: Evaluate function in Custom function
            sfpx

            Thanks for the reply but I know how to create a custom function with parameters

            The thing is that in the Custom Function editor it seems that we are unable to specify anything for the Optional Field of the evaluate function.

             

            In other words.

            This custom function with parameter named "Condition"  will work

            Evaluate(GetValue(Condition;1);[])=1; GetValue(c;2)


            Example that I can not do (parameters: Condition, OptF)

            Evaluate(GetValue(Condition;1);[OptF])=1; GetValue(c;2)


            The OptF between the brackets will be refused by the function editor.


            It wants a field so I guess it's not possible inside the custom function.


            • 3. Re: Evaluate function in Custom function
              user19752

              You can't write brackets itself in Evaluate() function. It says "it is option". (But I think you already know this)

               

              Evaluate ( GetValue ( Condition ; 1 ) ; someField )

               

              And, the 2nd (and more) parameter should be field reference (not value), so using in custom function become

               

              Evaluate ( GetValue ( Condition ; 1 ) ; Evaluate ( textParamterOfFiledName ) )

               

              Second Evaluate() can be GetField(), and there may need tablename:: in parameter.

               

              I don't know how can you make "optional parameter" in custom function itself (may not be able).

               

              CustomFunc ( needThis [ ; option ] )

              • 4. Re: Evaluate function in Custom function
                DavidJondreau

                You cannot specify optional parameters in custom functions.

                • 5. Re: Evaluate function in Custom function
                  sfpx

                  For the record I'm not trying to setup a custom function with an optional parameter.

                   

                  I'm trying to enter the optional field of the evaluate function inside a custom function.

                   

                  I don't think it's possible.

                   

                  Evaluate ( GetValue ( Condition ; 1 ) ; Evaluate ( textParamterOfFiledName ) )

                   

                  will not be accepted inside the editor.

                  Try it

                  • 6. Re: Evaluate function in Custom function
                    DavidJondreau

                    Ah, I see now.

                     

                    I believe only literal field names can be entered as the optional parameter in Evaluate(). I don't know how the engine enforces that, but it seems to hold true for field calculations, custom functions, and the data viewer.

                     

                    You may be able to work around it...for example, Evaluate() will show a different error if you put a "fake" field name like table::field as the parameter. But that's pretty kludgy.

                    • 7. Re: Evaluate function in Custom function
                      user19752

                      Ouch, I should have tested such things before post.

                       

                      The option parameter have meaning only if the function is used in field calculation, so the behavior (can't use in custom function) is reasonable.

                       

                      Your function may be able to be defined as

                       

                      Case

                      (

                      Evaluate(GetValue(conditions;1))=1; GetValue(c;2);

                      Evaluate(GetValue(conditions;3))=1; GetValue(c;4);

                      ...

                      then used as

                      Evaluate ( "cf ( conditions ; c )" ; Ofield )

                      • 8. Re: Evaluate function in Custom function
                        sfpx

                        Thanks again user19752