I'm using my iPhone at the moment so downloading the file doesn't help. Your script looks correct so you need to check your data, relationships, and layout design for problems.
yeh thats what i am struggling with as i can not see what I am doing wrong...
I downloaded your file. You have several different problems: First, your actual script is:
- Set Variable [ $ID_Contact; Value:"/*Companies Details::k_ID_Contact*/" ]
- Freeze Window
- Go to Layout [ “Notes” (Notes) ]
- New Record/Request
- Set Field [ Notes::kf_ID_Contact; $ID_Contact ]
- Commit Records/Requests [ Skip data entry validation; No dialog ]
- Go to Layout [ original layout ]
- Go to Field [ Notes::Text ]
First, the reference to the ID field was enclosed in /* comment */ brackets which keeps FileMaker from evaluating the reference to the field. Then, that text was enclosed in quotes so your $ID_Contact variable was getting set to the literal text: /* ID_Contact */.
Then, ID_Contact is the wrong field. It does not exist in your companies_Details table. I would guess that you imported or copy/pasted this script from a starter solution where such a field did exist. You need to remove this quoted text and replace it with a reference to your ProjectID field as this is the match field that links a record in Companies_Details to a record in Notes.
BTW, another way to add records to a portal is to double click the relationship line in Manage | Database | Relationships and select "allow creation of records via this relationship" for the Portal's table occurrence box. This allows you to create new notes directly in the portal simply by entering data into a field in the bottom, blank "add row" that now appears in your portal and you do not need any button or script to do so. (But yes, there are some good reasons for using a button and script--especially if you are going to add a lot of records to the portal and want the newest record to appear first in the portal.)
Thanks for taking the time to download and thanks for the advise. I have made the changes that you recommended and that has done the trick.
A couple of things:
1. Firstly it now seems that I no longer need the "add a note" button as it automatically puts in a new box. Only bad thing about this is that I want the latest comment on top and if it put the automatic box there will be a blank box each time?
2. I did put it in order of "TimeStamp Creation" - I want to have the latest on the top and it pushes all the others ones down... At the moment it isn't doing that.
3. I wanted to have a "TimeStamp Creation" and "UserName_Created" in the text box for comment... I have used the following....
TextColor ( TextStyleAdd ( TextSize ( Lower ( TimeStamp_Creation ) & " by " & UserName_Created ; 9 ) ; Italic ) ; RGB ( 136 ; 136 ; 136 ) )& TextSizeRemove ("¶"; 9 )
It does not work for some reason.
4. I've uploaded the changed file if you want to take a look:
Many thanks for you help and time it is very much appreciated.
1. This is why I presented the method of using "allow creation of records.." as an option to your current design. The add row is always comes after the last actual record in your portal and this is often not ideal.
2. It does put most recent record at the top for me when I test your copy with a corrected script.
3. This also works for me, but I do not recommend that you do that. Instead, put the actual timestamp and user fields in the portal row located above the note field. This can even be set up as a combination of layout text and merge fields to exactly reproduce the format shown, but in a line above your note field.
Thanks very much for you help!!
Just a quick add-on question to this..
I am just adjust the "print layout" to include the notes section. However the results that I am achieving is that it only shows the first comment from the notes section?
If you put a portal on a layout and print from that layout, only the rows that are visible without scrolling the portal will print.
The best option if you want to print all portal records is to set up a list view layout for printing purposes that is based on the portal's table. You can include fields from the parent record and use a script to pull up just the portal records linked to the current parent record.
Second best is to make your portal many rows tall and set it to "slide up", "resize enclosing part". This will reduce the number of portal rows printed to just the number of records in your portal but will not expand to add more rows.
or another "second best" might be to define a calculation field in your companies_Details table that uses List to list all your comments in a single field that can also be set to slide up/resize. This would allow each portal row to use just enough space to display that particular note.
Thanks for all your help Phil, as you can see my knowledge is quite limited.
That just sounds too complicated for me to achieve.
The starter solution that comes with FileMaker 13 uses the list view method for printing invoices (which have a portal to another table for line items). You can look that solution over to see how this can be setup.