Jump 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 correct "Else if" in script

Featured Replies

I have a FMP solution that is used to print box labels for our products, prior to shipping to customers.  We have many layouts, which represent the label format for each customer's specific requirements.  For context, the layouts are named as "Barcode-" and a customer code.  For example:

Customer Name = Magna

Customer code = MAG

Layout name = "Barcode-MAG"

If a customer does not have a specific requirement, we default to a layout named "Barcode-Default".

 

Currently, we have a printing script, with the following steps, which are used to "check for a customer specific layout" and revert to the default layout, if none exists.  The steps (which work) are:

# GO TO CUSTOMER SPECIFIC LABEL FORMAT

Go to Layout [ "Barcode-"  &  $$BCLayoutName ; Animation: None ]

If [ Get( LastError ) ]

Go to Layout [ “Barcode-Default” (FINAL INSPECTION SHEET) ; Animation: None ]

End If

 

I'm trying to add another step to the logic, which checks for a part specific layout.  In this case, let's call the layout "Barcode-MAG 24".  I would like the sequence to follow the below logic:

  1. Check for part specific layout. i.e, "Barcode-MAG 24"
  2. If none found (error), then check for customer specific layout.  i.e. "Barcode-MAG"
  3. If none found (error), then go to for default layout.  i.e. "Barcode-Default"

I created the below steps, however, it is not working.  I believe that my use of Else if is incorrect, but wanted to get some help with best practices before I go further.

 

# GO TO CUSTOMER SPECIFIC LABEL FORMAT-NEW | BCC-2024/11/12

Go to Layout [ "Barcode-"  &  $$BCLayoutMISCID ; Animation: None ]

If [ Get( LastError ) ]

Go to Layout [ "Barcode-"  &  $$BCLayoutName ; Animation: None ]

Else If [ Get( LastError ) ]

Go to Layout [ “Barcode-Default” (FINAL INSPECTION SHEET) ; Animation: None ]

End If

 

Please advise?

To answer your question as asked: I don't see a place for an Else If clause here. It's just a couple of nested Ifs:

Go to Layout [ "Barcode-" & $$BCLayoutMISCID ]
If [ Get ( LastError ) ]
   Go to Layout [ "Barcode-" & $$BCLayoutName ] 
   If [ Get ( LastError ) ]
      Go to Layout [ "Barcode-Default" ] 
   End If
End If

Side note: do you really need global ($$)variables for this?


However, I think that instead of trying blindly a succession of layout names and testing for error, I would prefer to calculate the layout name we want to go to and go to it directly. To do this, we can check if each proposed layout name appears in the list of layouts we can get from the LayoutNames() function - something like:

Let ( [
all = LayoutNames ( "") ;
part = "Barcode-" & $partCode ;
cust = "Barcode-" & $custCode 
] ;
Case (
not IsEmpty ( FilterValues ( part ; all ) ) ; part ;
not IsEmpty ( FilterValues ( cust ; all ) ) ; cust ;
"Barcode-Default"
)
)

or perhaps more succinctly:

Let ( [
candidateLayouts = List ( 
"Barcode-" & $partCode ;
"Barcode-" & $custCode ;
"Barcode-Default" 
) ;
existingLayouts = FilterValues ( candidateLayouts ; LayoutNames ( "" ) )
] ;
GetValue ( existingLayouts ; 1 )
)

Caveat: untested.

 

Create an account or sign in to comment

Important Information

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

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.