Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    if else logic in Formula Builder

    Is it possible to put if else type logic into the formula Builder. For example, something like...

    if(A>B){return C;}else{return D;}

    I tried that and it says that if is an unidentified token.

    #2
    No, the FormulaBuilder isn't intended for full conditional logic, iterations, etc.

    You could add your own advanced version of formulas that allows full JavaScript coding (maybe with a syntax highlighting editor), or a structured editor similar to hilites where one or the other formula is used based on AdvancedCriteria.

    Comment


      #3
      I'm working on a fairly simple version of this that lets power users define functions that can be used in Formula Builder. Is there any way to make a "record" object available so that a power user could access various properties on a ListGridRecord other than those being displayed in the Formula Builder "Source Field" list?

      Also, I did need to patch your code in one place. It probably makes sense to include something similar in your main code. It just ensures that the formulaFunction is valid and fires without exception. If the function is not valid or throws an exception, then it returns null. This was a fatal error (as in, our app wouldn't load at all) that happens when a user creates a formula using a function that later on gets removed or renamed for some reason...

      Code:
      	isc.Canvas.getPrototype().addProperties({
      		
      		getFormulaFieldValue:function(_1,_2){
      			var formulaFunction=this.getFormulaFunction(_1);
      			if(formulaFunction!=null && isA.Function(formulaFunction)){
      				try{
      					return formulaFunction(_2,this);
      				}catch(e){
      					isc.Log.logInfo("exception calling formulaFunction in getFormulaFieldValue, e:" + e)
      					return null;
      				}
      			}else{
      				return null;
      			}
      		}
      	
      	})

      Comment


        #4
        You should find that "record" is available as a variable for passing to MathFunctions. There's no way to get to it without it being passed in.

        We'll check on the error handling.

        Comment


          #5
          Hi, can you clarify how I can pass record to the Math functions? I don't see any mention of this in the docs so not sure if this is just an undocumented feature or if I'm looking in the wrong place?

          http://www.smartclient.com/docs/8.2/a/b/c/go.html#class..MathFunction

          Comment


            #6
            Literally myFunction(record) in the formula.

            The ability to pass the record this way wasn't doc'd, but we're making it official.

            Comment


              #7
              FYI, I know this thread is a bit old but I'm realizing that while Formula Builder doesn't allow for complex if/then logic, native javascript conditional statements do work and allow for some more complex logic in Formula Builder. Perhaps something to highlight in the standard help text that shows up for Formula Builder?

              Comment


                #8
                It's intentionally not documented since it would badly confuse most end users. But you can of course document it if your end users are smarter :)

                Consider also adding a custom MathFunction similar to Excel's IFF().

                Comment

                Working...
                X