Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×

This topic is 4001 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Posted

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

Posted

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

  • Like 2
Posted

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 …

  • Like 2
Posted

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

Posted
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" ) 
Posted

 

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:

Posted

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:

 

This topic is 4001 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

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