Is there a way to make a field so that there can only be one yes per FK? - filemaker

I am on Filemaker 18 Pro and new to Filemaker in general. I created a table of Clients and a table of Properties. One client can have multiple properties (ie One to Many relationship). I want to have a flag to indicate that the property is the Client's Primary Address. So basically the field will be:
isPrimary = "Yes" or isPrimary = "No".
There can only be one "Yes" per Client ID
There HAS to be one "Yes" value per Client ID
If you add "Yes" then it will change the existing "Yes" to "No"
Is there a best practice for doing this?

Is there a best practice for doing this?
Yes, there is. If only one property can be the client's primary address, then the identity of the primary address is an attribute of the client, and should be recorded in a field of the Client's table - e.g. a Number field storing the selected property's PropertyID.
To "flag" the primary address, use an unstored calculation, or a conditionally formatted object, using the formula:
Clients::PrimaryAddressID = PropertyID
In this arrangement, selecting a new primary address will automatically remove the flag from the previous address and place it on the newly selected one.
P.S.
It is much more convenient to use the values 0 and 1 (or empty and 1) for Boolean fields. The field itself can be formatted to display as "Yes" or "No".

You can loop the Properties portal/records and set "No" for other records.

Related

Code to assign an ID when button is clicked

I have designed a simple database to keep track of company contacts. Now, I am building a form to allow employees to add contacts to the database.
On the form itself, I have all the columns except the primary key (contactID) tied to a text box. I would like the contactID value to be (the total number of entered contacts + 1) when the Add button is clicked. Basically, the first contact entered will have a contactID of 1 (0 + 1 = 1). Maybe the COUNT command factors in?
So, I am looking for assistance with what code I should place in the .Click event. Perhaps it would help to know how similar FoxPro is to SQL.
Thanks
The method you recommend for assigning ContactIDs is not a good idea. If two people are using the application at the same time, they could each create a record with the same ContactID.
My recommendation is that you use VFP's AutoIncrementing Integer capability. That is, set the relevant column to be Integer (AutoInc) in the Table Designer. Then, each new row gets the next available value, but you don't have to do any work to make it happen.
There are various ways to do this. Probably the simplest is to attempt to lock the table with flock() when saving, and if successful do:
calc max id_field to lnMax
Then when inserting your new record use lnMax+1 as the id_field value. Don't forget to
unlock all
... after saving. You'll want to ensure that 'id_field' has an index tag on it, and that you handle the case where someone else might have the table locked.
You can also do it more 'automagically' with a stored procedure.

Hide elements in list view for non active records in Filemaker

I've got a list view of a number of records. I would want to hide certain layout elements on the records which isn't the active one. Is this possible?
It should be possible with the "Hide object when"-functionality, but I'm not sure what the calculation should be.
I'm using Filemaker 13.
You can use a Script Trigger to set a global variable (e.g., $$ID) with that record's Primary Key (ID) when a record is loaded, then hide the button/layout object if not $$ID = PKID.
Adapted from the technique at http://forums.filemaker.com/posts/e591b47fdc.
Just create a statistic field in your table that counts the current number of any field that is filled in every record. An ID or timestamp would be the best guess. Then hide your portal object(s) in the inspector with "YourFieldName" <> Get(ActiveRecordNumber). Should be done.

Generating a customer ID in a form

I have a customer table 'tblCustomer' that contains a primary key column called CustID. CustID refers to the Customer as their own ID number.
Now, I am in the process of creating a form that will allow people to add new customers. To do that, I need to generate a new CustID. My CustID starts at '10000' and go up by 1 each time. It is important to note that this field is a text field, not a number field.
There must be an ID, otherwise the record cannot be created as the primary key field is a mandatory field and is also tied to other relationships in the database.
As such, I am creating a button next to the ID field on the form that will generate an ID in the textbox. It needs to start at whatever the custID's highest key value is and increment it by 1. The problem is that it is a text field and cannot change.
I am unsure how to do this, personally. I have tackled it quite a few ways but all lead me back to the same spot - I don't know how to do this with custID being a text value rather than a numerical value. I have been thinking of doing a conversion of some sort as the calculation occurs but I have no idea how to do this at all.
I'm a bit of a newbie with Access, so any help would be appreciated!
Assuming that all CustID's are numbers, you can do the following to get a new ID:
Dim strMax As String
Dim intMax As Integer
strMax = DMax("CustID", "<your table name>")
intMax = CInt(strMax) + 1
strMax will hold the current maximum id, and intMax will hold the new ID. If strMax contains a non numeric value however this code will fail - you would need an error handler to work around it.
Just need to put it in the buttons click event.
Hope this helps!
Simon

Diffrence between "Created On" and "Record Created On"

In CRM, when I'm, trying to set up a work flow, I get to choose the timeout to be related to a certain entity's creation time. There are three fields to relate to.
Record Created On
Created On
Modified On
While the last one is very obvious, I can't see any logical difference between the two others.
The difference is that Created On (createdon) is filled out automatcally by the server when you actually create the record, while Record Created On (overriddencreatedon) will usually be null (unless the record was imported into CRM and you chose to explicitly override the record creation date to match when it was created in another system).
You should use the first and skip the latter, as it's not supported (as far I've got it right when I talked to a MVP about it). Why it show, she had no idea and neither do I. Maybe #JamesWood has a shot. He usually does. (sucking-up in progress)
I've never used the latter and I believe you'll keep your hair off-grey and on-head if you stick to the same approach.
From the SDK:
The createdon attribute specifies the date and time that the record was created. To import data in the createdon attribute, map the source column that contains this data to the overriddencreatedon attribute.
During import, the record’s createdon attribute is updated with the value that was mapped to the overriddencreatedon attribute and the overriddencreatedon attribute is set to the date and time that the data was imported.
If no source value is mapped to the overriddencreatedon attribute, the createdon attribute is set to the date and time that the data was imported and the overriddencreatedon attribute is not set to any value.
Link to BlogSpot
Link to Social MSDN

Primary / Default ABMultiValue property?

I need a user to enter their name, phone number, and email address. To help them out, if they enter any one of the three, I want to look up that value in their Address book and populate the remaining fields. For example, if they enter their name, I'll look them up, and populate the email and phone number fields.
Email and phone numbers are ABMultivalue properties, however, and most people have more than one email and phone. Does the iPhone address book have the concept of a primary or default value for those properties that are ABMultiValue?
Thanks!
There is no primary/default value. I would simply assume that the first value is the primary/default value. It's true for most of my contacts. Otherwise if there are multiple values you could let the user choose the one they want, but you need to make a good UI to support it, so the first alternative is much simpler.