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.

Replace IF/END IF with calc and LET and variables

Featured Replies

  • Author

In a DB, i've numerous fields and relationships, all named at the end with a "number".

I use scripts with getparameters and IF/END IF structures.

The problem is : it creates large script, with repetiting structures.

My question : would it be possible to use a calc with the LET function and a variable to replace all thoses IF/END IF structures (or CASE structure within a calc field) ?

Example :

if getparameters = 1 then set field RELATION1::FIELD1="aaaaaaa"

if getparameters = 2 then set field RELATION2::FIELD2="bbbbbbb"

if getparameters = 3 then set field RELATION3::FIELD3="ccccccc"

if getparameters = 4 then set field RELATION4::FIELD4="ddddddd

I "feel" that I can do something with LET and/or EVALUATE, but I really have problems to use this rather complex function...

Can you help me ?

In a DB, i've numerous fields and relationships, all named at the end with a "number".

I use scripts with getparameters and IF/END IF structures.

The problem is : it creates large script, with repetiting structures.

My question : would it be possible to use a calc with the LET function and a variable to replace all thoses IF/END IF structures (or CASE structure within a calc field) ?

Example :

if getparameters = 1 then set field RELATION1::FIELD1="aaaaaaa"

if getparameters = 2 then set field RELATION2::FIELD2="bbbbbbb"

if getparameters = 3 then set field RELATION3::FIELD3="ccccccc"

if getparameters = 4 then set field RELATION4::FIELD4="ddddddd

I "feel" that I can do something with LET and/or EVALUATE, but I really have problems to use this rather complex function...

Can you help me ?

  • Author

In a DB, i've numerous fields and relationships, all named at the end with a "number".

I use scripts with getparameters and IF/END IF structures.

The problem is : it creates large script, with repetiting structures.

My question : would it be possible to use a calc with the LET function and a variable to replace all thoses IF/END IF structures (or CASE structure within a calc field) ?

Example :

if getparameters = 1 then set field RELATION1::FIELD1="aaaaaaa"

if getparameters = 2 then set field RELATION2::FIELD2="bbbbbbb"

if getparameters = 3 then set field RELATION3::FIELD3="ccccccc"

if getparameters = 4 then set field RELATION4::FIELD4="ddddddd

I "feel" that I can do something with LET and/or EVALUATE, but I really have problems to use this rather complex function...

Can you help me ?

You could do a single script step like:

Set Field [ RELATION1::FIELD1 ; Case ( getparameters = 1 ; "aaaaaaa" ; getparameters = 2 ; "bbbbbbb" ; getparameters = 3 ; "ccccccc" ; getparameters = 4 ; "ddddddd" ) ]

or:

Set Field [ RELATION1::FIELD1 ; Choose ( getparameters - 1 ; "aaaaaaa" ; "bbbbbbb" ; "ccccccc" ; "ddddddd" ) ]

You could do a single script step like:

Set Field [ RELATION1::FIELD1 ; Case ( getparameters = 1 ; "aaaaaaa" ; getparameters = 2 ; "bbbbbbb" ; getparameters = 3 ; "ccccccc" ; getparameters = 4 ; "ddddddd" ) ]

or:

Set Field [ RELATION1::FIELD1 ; Choose ( getparameters - 1 ; "aaaaaaa" ; "bbbbbbb" ; "ccccccc" ; "ddddddd" ) ]

You could do a single script step like:

Set Field [ RELATION1::FIELD1 ; Case ( getparameters = 1 ; "aaaaaaa" ; getparameters = 2 ; "bbbbbbb" ; getparameters = 3 ; "ccccccc" ; getparameters = 4 ; "ddddddd" ) ]

or:

Set Field [ RELATION1::FIELD1 ; Choose ( getparameters - 1 ; "aaaaaaa" ; "bbbbbbb" ; "ccccccc" ; "ddddddd" ) ]

  • Author

Yes of course. But the point is to use the getparameter as a variable to address (identify) different fields and relationships.

fieldX

relationx::fieldX

where X is the getparameter. This is the tricky part ;-)

  • Author

Yes of course. But the point is to use the getparameter as a variable to address (identify) different fields and relationships.

fieldX

relationx::fieldX

where X is the getparameter. This is the tricky part ;-)

  • Author

Yes of course. But the point is to use the getparameter as a variable to address (identify) different fields and relationships.

fieldX

relationx::fieldX

where X is the getparameter. This is the tricky part ;-)

Sorry - didn't notice you have changed fields. Then the only thing you can do is use Else If to trim it down a bit. There is no way to dynamically specify which field to Set[].

Sorry - didn't notice you have changed fields. Then the only thing you can do is use Else If to trim it down a bit. There is no way to dynamically specify which field to Set[].

Sorry - didn't notice you have changed fields. Then the only thing you can do is use Else If to trim it down a bit. There is no way to dynamically specify which field to Set[].

  • Author

Sorry Comment, english is not my native language so it's a little bit difficult to express myself.

I know that within a script you can not dynamically specify which field to Set[]

In fact, i would like to use it into the "calculated result" part of a Set Field[]

In this cas, i think with LET and EVALUATE you can dynamically "name" a field.

What do u think about it ?

  • Author

Sorry Comment, english is not my native language so it's a little bit difficult to express myself.

I know that within a script you can not dynamically specify which field to Set[]

In fact, i would like to use it into the "calculated result" part of a Set Field[]

In this cas, i think with LET and EVALUATE you can dynamically "name" a field.

What do u think about it ?

  • Author

Sorry Comment, english is not my native language so it's a little bit difficult to express myself.

I know that within a script you can not dynamically specify which field to Set[]

In fact, i would like to use it into the "calculated result" part of a Set Field[]

In this cas, i think with LET and EVALUATE you can dynamically "name" a field.

What do u think about it ?

Set Field[] has two parts: 1. WHICH field; 2. WHAT to put in this field.

The first part cannot be specified by a calculation. The calculation only affects the second part. Let() and Evaluate() are functions that you can use in the calculation, but they cannot change the LOCATION of the calculation's result.

Therefore, your example of:

If TRUE, Set Field X to something ; if FALSE, Set Field Y to something

is impossible as a calculation. It must be done by script steps.

You can only select which field is REFERENCED by a calculation. For example, if you have 2 fields named Field1 and Field2, you can write a calculation like:

GetField("Field" & Get(ScriptParameter) )

This will return the CONTENT of Field1 when ScriptParameter="1", the CONTENT of Field2 when ScriptParameter="2", and an error otherwise.

Set Field[] has two parts: 1. WHICH field; 2. WHAT to put in this field.

The first part cannot be specified by a calculation. The calculation only affects the second part. Let() and Evaluate() are functions that you can use in the calculation, but they cannot change the LOCATION of the calculation's result.

Therefore, your example of:

If TRUE, Set Field X to something ; if FALSE, Set Field Y to something

is impossible as a calculation. It must be done by script steps.

You can only select which field is REFERENCED by a calculation. For example, if you have 2 fields named Field1 and Field2, you can write a calculation like:

GetField("Field" & Get(ScriptParameter) )

This will return the CONTENT of Field1 when ScriptParameter="1", the CONTENT of Field2 when ScriptParameter="2", and an error otherwise.

Set Field[] has two parts: 1. WHICH field; 2. WHAT to put in this field.

The first part cannot be specified by a calculation. The calculation only affects the second part. Let() and Evaluate() are functions that you can use in the calculation, but they cannot change the LOCATION of the calculation's result.

Therefore, your example of:

If TRUE, Set Field X to something ; if FALSE, Set Field Y to something

is impossible as a calculation. It must be done by script steps.

You can only select which field is REFERENCED by a calculation. For example, if you have 2 fields named Field1 and Field2, you can write a calculation like:

GetField("Field" & Get(ScriptParameter) )

This will return the CONTENT of Field1 when ScriptParameter="1", the CONTENT of Field2 when ScriptParameter="2", and an error otherwise.

  • Author

Yes ! Thank you for GetField. It's one solution.

  • Author

Yes ! Thank you for GetField. It's one solution.

  • Author

Yes ! Thank you for GetField. It's one solution.

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.