Product Logo

CNS Query

Query your databases without relationships.

Set Field


Set Field example database

This example shows how easy it is to Set a Field in your table from any calculation, specifying the name of the Field to Set dynamically. Select a field name from the “Field Name” menu, type a new value into the “Field Value” field, and press the “Set Field” button. This button calls the “Set Field” script to set the field you specified with the value you specified and returns the result to the “Result” field.

Download Example File

FileMaker 7–11 Example

FileMaker 12 Example

View Calculation

To see the calculation that tells the plug-in what to do, open ScriptMaker/Manage Scripts by going to the “Scripts” menu, and choosing ScriptMaker/Manage Scripts. Once in ScriptMaker/Manage Scripts, double click on the ‘Set Field’ script. Note that we are using the “Set Field” script step which consists of two settings. The “Specify target field” button allows you to choose which field you want to set. In our case we want to set the “Result” field. The second specify button is where the CNS Query calculation exists. Click this button to see the calculation used to tell the plug-in what to do. The following image shows the first “Set Field” script step calculation. You can view the other script step calculations by following the same procedure.

Set Field Function

The “Set Field” function is very easy to use. In our script, it looks like this:

CNSQuery_SetFieldValueByID( “” ; Set Field::Field Name ; Set Field::Field Value )

The first parameter is where you specify the name of the Table you want to Add the Field to. Since we are updating a field in the current table, we can just specify “” here, otherwise this would be the name of a Table. Note that if you want to set a field in a different table, you do not need to define a relationship to that other table. Even if you do have a relationship to that table, it does not have to be valid at the time you call this function. You can also set fields in tables that are in other database files. All you need is a Table Occurrence of the external table in your Relationship Graph in order to set a field in the table.

The second parameter is where you specify the Name for the Field you want to set. We are using the value from the “Field Name” menu. The third parameter is the new Value for the Field. We are using the value we typed in the “Field Value” field. The “CNSQuery_SetFieldByID” function has four other parameters that we are not using here. The fourth parameter is the “FMRecID” parameter which is where the “ByID” part of “CNSQuery_SetFieldByID” function name comes from. By default, you can leave off the fourth parameter and the plug-in will set the field you specify in the current record. However, if you want to set the field you specify in a different record, and you know the internal FileMaker Record ID of that record, then you would specify it here. There is a companion function named “CNSQuery_SetFieldByFind” which allows you to specify some Find Criteria for the plug-in to locate the record you want to update if you don’t know the internal FileMaker Record ID. (Note: you can find the Internal FileMaker Record ID of a field using the Get( RecordID ) function.)

The remaining three parameters to the CNSQuery_SetFieldByID function allow you to skip double-checking the Table, Field Name, and Record ID parameters. Skipping these checks will speed the plug-in up a little bit if you know all the values are valid.