Jump to content
Server Maintenance This Week. ×

"Universal" Constrain --- Syntax


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

Recommended Posts

Greets, all:

I'm trying to set up a part of a script where it constrains on a Primary Key to isolate a record, irrespective of its table, and I'm stuck on the syntax.

The set-up:

Variable: $_TableName = Get (LayoutTableName)

The Primary Key: They all have the same naming convention in all the tables: _kplt_TableNameID" . The value inside every Primary Key is set by  Get ( UUID ).

 

Where I'm getting hung up is the Set Field syntax; the script (so far) goes like this:

 

Enter Find Mode [Pause: Off]

Set Field [ Evaluate ( $_TableName & "::" & "_kplt__" & $_Tablename & "ID" ) ;  ????? ]

Set Error Capture [ON]

Constrain Found Set [  ]

 

What do I use for the ??????  Also, is there a more elegant way of doing the same thing by using the Find Matching Records command?

 

As always, thanks in advance for your help!

Link to comment
Share on other sites

 

14 minutes ago, WF7A said:

I'm trying to set up a part of a script where it constrains on a Primary Key to isolate a record

Do you mean you want to isolate the current record, so that it becomes the only record in the found set?

Link to comment
Share on other sites

First, have a look at this classic:
https://fmforums.com/topic/97497-constrain-to-current-record/?do=findComment&comment=443142

 

To do it the way you have started, you would need something like:

Set Variable [ $fieldName; Value:Get ( LayoutTableName ) & "::" & "_kplt__" & Get ( LayoutTableName ) & "ID" ] 
Set Variable [ $id; Value:GetField ( $fieldName ) ]
Enter Find Mode [ ]
Set Field By Name [ $fieldName; $id ]
Perform Find []

Note that the Evaluate() function is not needed for this. Also there is very little point in setting a variable to one of the Get() functions: most, if not all of them are just that: variables.

 

1 hour ago, WF7A said:

is there a more elegant way of doing the same thing by using the Find Matching Records command?

I don't think so, because Find Matching Records[] does not allow the use of a calculated field name.

Link to comment
Share on other sites

Ah! Thanks.

Just for the sake of (an) argument, say I wanted to constrain to a specific field but its contents could be anything (not empty); what would I replace "ID" with?

Link to comment
Share on other sites

The whole idea is predicated on you using a consistent naming convention so that all your primary keys take the form:

"_kplt__" & Get ( LayoutTableName ) & "ID"

I wouldn't think you'd use that convention for every field in the table, that would be weird. So you wouldn't replace "ID" -- you'd completely replace that whole string with whatever field name you want to use. 

Link to comment
Share on other sites

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