If the Invoices::ContactIDFk field is blank then there is no relationship between Invoice and Contacts_Invoices (as that is what your relationship is based on) so your script step won't work as one side or the other doesn't have a related record. If you're on a layout/portal based on Invoices there is no related Contacts_Invoices record to pull the Contacts_Invoices::ID field from, or, if you're on a layout/portal based on Contacts_Invoices there is no related Invoice record in which to Set the ContactIDFk field.
Depending on what your process is there are several different options for this.
If you're creating the Invoice starting from a Contact record you can save the Contacts::ID in a variable and then assign that to the Invoice when it is created. Or, and based on your object names in the script snippet you provided it seems like this is what you are doing, on the Invoice there can be a client picker that allows the user to select the client and then it fills the Contacts::ID into the Invoice::ContactIdFk field.
In the example posted you are setting contactIDFk to invoice number not ID.
Hi guys, thanks for the response. I tried to work a bit with the information given but can't get to a solution that works.
I hope someone can show me how to do it so I can learn from that.
In attachment a testfile (login: Admin pw:8710).
I'm trying to get my
Layout: "CreateNewInvoice" Tab: "Klantgegevens" Link: "Toon alle klanten" to show a list of all clients where I can pick one from using the search.
Then it would need to populate the ContactIdFk field on Tab: Klantgegevens.
I tried working with a global field but didn't succeeded since it showed me the same value over all the invoice records.
Been trying to fix this for 1,5 day and it's driving me crazy. I am going on a 3 day Filemaker development course where they will teach me more about relationships but that doesn't help me at this moment of course. Trying to learn as much as I can lately. Course doesn't have a start date yet. Hope it will start soon.
Thanks for pointing out. I copied the wrong information sorry. Was confused by all the windows that were open.
I took a look at your file at made a few modifications:
- I added a Set Variable step in the "Select Client for Invoice" script that saves the current Invoice ID to a global variable before switching to the layout where they select the client.
- I created a script "Select Client for Invoice" that saves the Contacts_Invoices::Id from the selected Contact and then switches back to your CreateNewInvoice layout, finds the original invoice (using the global variable from above), and switches back to the Choose Client tab.
- I attached that script to the client's name in the ChooseInvoiceClient layout, so that clicking on the name takes you back to the invoice. (I'm sure you'll change it so that it doesn't show the client's ID, but rather their name.)
Hopefully this helps you see how it could be done. There are other options you might want to consider for choosing the client, such as a popover (as is used in FileMaker's Invoices template), or a card window (if you are using FM 16), or even a modal dialog window. These would allow you to choose the client without switching the layout completely.
Hopefully that will help you get started.
vbmservices-314dev.fmp12.zip 1.4 MB
many many thanks for your help. Works flawless and I will definitely learn from this.
I understand there are often more approaches you can follow with all their benefits and downsides. But at least now I know one possible solid solution and I can learn from it.
Again much appreciated.