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

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

Recommended Posts

Posted

Hi fmforums!

 

It's been a long time since I last made a post, as just searching through the available content here has usually answered my questions [if I search long enough]

 

I'm currently reworking my scripts so that they become universal in my database - less maintenance you see…

And I would like to know whether anyone can shed some light on a rambling question I have?

 

In all of the underlying tables, I have some regular number fields, such as: flag, delete, marker…

Dependent on their auto-enter calculation at record creation, they’re either 0 or 1.

 

I’m trying to change my script steps so that a script created is independent of any table, for example:

table_alpha::delete

table_bravo::delete

table_charlie::delete

 

…used to require three separate scripts to set each table record’s delete field, now just requires one script:

 

Set Variable [ $t ; Value:Get ( LayoutTableName ) ]

Set Variable [ $t ; Value: $t & "::delete" ]

Set Field By Name [ $t ; 1 ]

Commit Records/Requests

 

However, I presently seem to be hitting a wall on getting a field’s contents based on a variable generated in the script, for example:

 

table_alpha::marker

table_bravo::marker

table_charlie::marker

 

allows me to mark several records at a time in different tables, but I want to be able to toggle its field value to 0 or 1, through a script. So following the above line… ( assuming table_alpha::marker = 1 )

 

Set Variable [ $m ; Value:Get ( LayoutTableName ) ]

Set Variable [ $m ; Value: $m & "::marker" ]

Set Variable [ $flag ; Value:GetFieldName ( $m ) ]

 

… should return the value of "table_alpha::marker" to $flag if script is run from table_alpha, 

return the value of "table_bravo::marker" to $flag if script is run from table_bravo,

return the value of "table_charlie::marker" to $flag if script is run from table_charlie

 

then I would intend on continuing by testing $flag further along in the script

 

If [ $flag = 1 ]

do something

Else If [ $flag = 0 ]

do some other thing

End If

Commit Records/Requests

 

However, I've tried the following versions of the script step in red, with the following results (assuming table_alpha::marker = 1)

Set Variable [ $flag ; Value:GetFieldName ( $m ) ] = Error 5 - command is invalid

Set Variable [ $flag ; Value:GetFieldName ( "$m" ) ] = table_alpha::marker, instead of value of table_alpha::marker

Set Variable [ $flag ; Value:$m ] = table_alpha::marker, instead of value of table_alpha::marker

 

Any suggestions would be appreciated.

Posted

Hi Chris,

 

GetField() is what you need and a Boolean result.  Consider these steps:

 

Set Variable [ $field ; Get ( LayoutTableName ) & "::mark" ]

Set Field By Name [ $field ; not GetField ( $field ) ]

 

Boolean not 'field' will toggle a field from 0 to 1

  • Like 1
Posted

I don't know if you need the table occurrence name for other purposes, but if you're getting the contents of a field in the current local record, GetField does not need the table occurrence name; just the field name will do. (Set Field by Name, however, is more finicky.)

 

GetField ( "mark" ) = GetField ( Get ( LayoutTableName ) & "::mark" )

 

Also, your scripting might be more robust if the scripts accept the field names as parameters rather than rely on your naming convention. Field names, even field names dictated by convention, can and do change long after we've forgotten what's attached to them. Using the FileMakerStandards.org script parameter functions, the script parameter calculation to call one of your scripts for a particular table might be something like this:

 

# ( "deleteFieldName" ; GetFieldName ( TableAlpha::delete ) )

& # ( "markFieldName" ; GetFieldName ( TableAlpha::mark ) )

 

And the script might do something like:

 

Set Variable [$!; Value:#Assign ( Get ( ScriptParameter ) )]

...

Set Field by Name [$deleteFieldName; Value:False]

...

Set Field by Name [$markFieldName; Value:not GetField ( $markFieldName )]

  • 1 month later...
Posted

Apologies for not replying sooner, your solutions sparked off other ideas.

However, I found that the script wasn't picking up the current table name in a single script step. so I had to split steps thusly:

Set Variable [$table; Value:Get ( LayoutTableName )]
Set Variable [$table_flag; Value:$table & "::flag"]
Set Variable [$field; Value:GetField ( $table_flag )]
If [$field = 1]
Set Field By Name [$table_flag; 0]
Commit Records/Requests
Exit Script []
Else If [$field = 0]
Set Field By Name [$table_flag; 1]
Commit Records/Requests
Exit Script []
End If

Once corrected, I was able to handle both unmarking a record and flagging it for deletion.

…and some time after that, handle multiple randomly flagged records for unmarking and flagging for deletion.
…and a bit after that, handling multiple flagged records for grouping, scripting email replies, canned guides…

I now just have to update some 90 layouts with 30 individualised delete scripts to one script and I'll be a happy bunny! Oh and stick a marker button on each

Posted

If [$field = 1]

Set Field By Name [$table_flag; 0]

Commit Records/Requests

Exit Script []

Else If [$field = 0]

Set Field By Name [$table_flag; 1]

Commit Records/Requests

Exit Script []

End If

 

While you're spring cleaning …

 

Since you're setting the field and committing the record either case, it's shorter to write …

 

Set Field By Name [ $table_flag ; Case [ $field = 1 ; 0 ; 1 ) ]
Commit Records/Requests
Exit Script []
 
… but even shorter is …
Set Field By Name [$table_flag; not $field ]
Commit Records/Requests
Exit Script []
… as was previously suggested by LaRetta and Jeremy.

This topic is 3934 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.