Skip to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Help with script syntax - If [IsEmpty(…………….

Featured Replies

Just after some help getting the expression correct in this script:

 

If  IsEmpty(pk_InvoiceID) ; "No Invoice exists." ; "" 

 

Can't seem to get the expression right according to the "Specify Calculation window" - usually is looking for additional operators, or I have too many/not enough "(" or ")".

 

When building the line (I'm adding to an existing script), I use the script editor to start, then select "If" in the left hand window, and then start to build the expression in the 'specify calculation' window.

 

TIA

No closing parentheses in your calc

If  IsEmpty(pk_InvoiceID) ; "No Invoice exists." ; "" 

 

 

I am assuming (as your title would suggest) that you are speaking of the If[] script step - not the If() function. In the If[] script step, you specify only a test, not a result. The "result" is the script steps following the If[] step, that will be executed only if the test returns true. Try something like:

 

If [ IsEmpty ( YourTable::pk_InvoiceID ) ]

 # do some  things

Else

 # do other things

End If

If you're using this with the If [] script step, you need a calculation that gives you a Boolean (True/False) result, which you use to decide if the step(s) enclosed in the If / End If block will be performed or not. 

So you'd write

If [ IsEmpty ( pk_InvoiceID ) /* is either True or False */  ]
  some other step(s), e.g. Show Custom Dialog with your message
End If

Note the difference between the If() function and the If[] script step. The formula

If ( IsEmpty ( pk_InvoiceID ) ; "No Invoice exists." ) // gives you a text result or (implicitly) an empty result

uses If () to calculate a text result, e.g. for a calculation field or a variable.

 

EDIT: Oops, why did I even bother …

  • Author

Thank you for that distinction (Your assumption was spot on) - I had the feeling I was more or less constructing an If…Then expression, but in the one line - which didn't seem right.

 

Now I understand the difference. I was trying to specify a test AND a result using the If[] script step, but constructing the expression as per the If() function (which does contain a result, as well as the test, in the one expression).

 

One question that arises - when would you use the If (IsEmpty (Field) ; "Result A" ; "Result B")  'function', in this form, and not in a script step?

 

Cheers

 

I am assuming (as your title would suggest) that you are speaking of the If[] script step - not the If() function. In the If[] script step, you specify only a test, not a result. The "result" is the script steps following the If[] step, that will be executed only if the test returns true. Try something like:

 

If [ IsEmpty ( YourTable::pk_InvoiceID ) ]

 # do some  things

Else

 # do other things

End If

when would you use the If (IsEmpty (Field) ; "Result A" ; "Result B")  'function', in this form

 

One example out of many possible:

If ( IsEmpty ( DateCompleted  ) ; "In Progress" ; "Completed" ) 

 

One example out of many possible:

If ( IsEmpty ( DateCompleted  ) ; "In Progress" ; "Completed" ) 

 

To take this all a step further ... if you plan to set same field either way, instead of this:

If [ IsEmpty ( DateCompleted ) ]
  Set Field [ Status ; "In Progress" ]
Else
  Set Field [ Status ; "Completed" ]
End If

... you could use single calculation thus:

Set Field [ Status ; If ( IsEmpty ( DateCompleted ) ; "In Progress" ; "Completed" ) ]

When scripting, I always have to ask myself whether it could be condensed.  Sometimes good use of the functions ( as long as clarity is maintained ) can decrease the script steps needed and an If() function would be faster than an If[] script step; not that I'm telling YOU that, Michael, but for others who might read along. 

 

and yes of course, we could use text block and conditional formatting and many other techniques and this example Status field might not be necessary at all but that's another story.   :laugh2:

  • Author

Thankyou both for this clarification. From the reading I have done (FTS, Functions Ref in particular), this sort of distinction between the use of  If[] and If (), isn't really that clear. 

 

I really appreciate the time you guys put in to helping fledglings like myself. I hope one day I'll have the knowledge base/experience to draw from to help others on here similarly :grad: . 

 

Thank you…..

………….no, really……

………………..…..THANKYOU!  :thumbsup:

 

 

 

One example out of many possible:

If ( IsEmpty ( DateCompleted  ) ; "In Progress" ; "Completed" ) 

 

 

 

To take this all a step further ... if you plan to set same field either way, instead of this:

If [ IsEmpty ( DateCompleted ) ]
  Set Field [ Status ; "In Progress" ]
Else
  Set Field [ Status ; "Completed" ]
End If

... you could use single calculation thus:

Set Field [ Status ; If ( IsEmpty ( DateCompleted ) ; "In Progress" ; "Completed" ) ]

When scripting, I always have to ask myself whether it could be condensed.  Sometimes good use of the functions ( as long as clarity is maintained ) can decrease the script steps needed and an If() function would be faster than an If[] script step; not that I'm telling YOU that, Michael, but for others who might read along. 

 

and yes of course, we could use text block and conditional formatting and many other techniques and this example Status field might not be necessary at all but that's another story.   :laugh2:

 

Create an account or sign in to comment

Important Information

By using this site, you agree to our Terms of Use.

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.