5 Replies Latest reply on Sep 16, 2016 1:01 PM by David Moyer

    Custom Function Request

    coherentkris

      I need a custom function that i can replace this mess with...

      Substitute ( "<filter " &

      List (

      If ( IsEmpty ( field_one ) ; "" ; "field_one=" & Quote ( field_one ) ) ;

      If ( IsEmpty ( field_two ) ; "" ; "field_two=" & Quote ( field_two ) ) ;

      If ( IsEmpty ( field_three ) ; "" ; "field_three=" & Quote ( field_three ) )

      ) & " />" ; "¶" ; " " )

       

      This essentially turns a record into a line of xml.

      If record values field_one="family" and field_two=""" and field_three="values" would output

      <filter field_one="family" field_three="values" />

       

      I would like to supply a list of fields into the function.

       

      Been a long day and my brain is full.

        • 1. Re: Custom Function Request
          mikebeargie

          TransformFieldList recursive custom function

           

          Let ( [

             field = GetValue ( listOfFields ; 1 ) ;

             n = ValueCount ( listOfFields )

          ] ;

             If ( IsEmpty ( field ) ; "" ; " " & field & "=" & Quote ( field ) )
             & Case ( n > 1 ; TransformFieldList ( RightValues ( listOfFields ; n - 1 ) ) )

          )

           

          Then you would use it as such:

          Set Variable [ $list ; some list of fields ]

          Set Variable [ $output ; "<filter " & TransformFieldList($list) & " />" ]

           

          Most likely will need to adjust "field" so that it's actually getting the right context of table/field together to make it work as a CF.

          1 of 1 people found this helpful
          • 2. Re: Custom Function Request
            coherentkris

            Close but it returns
            the same value on both sides of the =

            For example

            Let (

            _fields = List ( class ; protected ) ;

            TransformFieldList ( _fields )

            )

            returns

            class="class"

            protected="protected"

             

            however this works...

            //expects a return delimited list of table::fields for evaluation

             

                Let ( [

             

                   field = GetValue ( listOfFields ; 1 ) ;

                   table = GetValue ( Substitute ( field ; "::" ; ¶ ) ; 1 ) ;

                   field_only = GetValue ( Substitute ( field ; "::" ; ¶ ) ; 2 ) ;

                   field_value = Evaluate ( field ) ;

                   n = ValueCount ( listOfFields )

             

                ] ;

             

                   If ( IsEmpty ( field_value ) ; "" ; " " & field_only & "=" & Quote ( field_value ) )

                   & Case ( n > 1 ; TransformFieldList ( RightValues ( listOfFields ; n - 1 ) ) )

             

                )

             

            Thanks for the kickstart MB!

            • 3. Re: Custom Function Request
              mikebeargie

              Yep, when you switch from a literal calculation to an abstract custom function you need to change some things around, hence my warning at the end of that about need to make modifications to pull the actual table/field values. Gald it worked.

              • 4. Re: Custom Function Request
                David Moyer

                Hey Kris,

                this custom function can be used to help clean up your custom function.  It's designed to deal with If IsEmpty, don't show, else show.

                I too invented this simple gem

                The usage here would be Merge ( field_one ; "field_one=\""; "\" " )

                • 5. Re: Custom Function Request
                  David Moyer

                  p.s. you can also use it, nested, to prevent showing the whole <filter> element if all of the fields are empty.