Can you help me understand how to set my script of "New Record/Request" to add a new record specifically to a Portal as oppose to my main table?
Thanks so much.
There are a couple of ways to create a new record in a related table (which is what a portal reflects).
1) If you set the relationship to allow the creation of related records, you can simply go to the last portal row (which will be empty) and use any number of script steps (such as Set Field, Insert, or Paste) to put data into the related fields. For example:
Go to Portal Row [ Last ]
Set Field [ relatedTable::field ; new data ]
Set Field [ relatedTable::field2 ; new data ]
Commit Records / Requests
2) You can also create a related record by going to a layout that's based on that related table (which is called the "context"), then executing your New Record / Request step, then going back to the original context. For example:
Go to Layout [ layout based on related table ]
New Record / Request
Go to Layout [ original layout ]
Thanks so much for your help.
I've tried the calculations you provided and am having some difficulty still. First off, I am not sure how to get ... ; new data ] at the end of my lines.
Also, my portal is drawing from two different fields. Is there a special technique I should use to jump from one field to the next? As of now, when I enter in my second data entry field, which ends up being the first field of a second table, the information enters into every other record.
I hope that makes sense
The examples I gave you were script steps, created using the Manage Scripts dialog (Scripts > Manage Scripts). That's where you'll go to create your script.
In order to insert the data you want into your new record (the part I have as "new data" above), you'll use the Calculation Dialog. To get there, you'll use the Set Field script step:
When you insert that into your script, you'll use the "Calculated result" button to tell FileMaker what data to insert:
I don't know what data you want to insert, but you would do that inside that dialog.
To insert the data into a different field, you use the "Specify target field" button and tell FileMaker what field you want to use. You'll do this for each Set Field command. Each command would address a different field, depending on what data you want to insert.
If I'm understanding what's going on correctly, I think you're probably sending the two Set Field commands to the same field in two different portal rows. You probably also have more than one Go to Portal Row command; you only need one. Just create a new script in the Manage Scripts dialog with the steps I have above, and it should be fine.
Thanks for following up.
I feel like I'm running in circles. I apologize.
I have set a new script to make sure everything is fresh, as my scripts either claim now they were deleted or are jumping to the wrong field.
I still do not see where "new data" can be applied, as all my fields are data punch ins thus I do not believe require for me to specify calculations.
The table and the portal do have a relationship table between them, does this affect it?
I am trying to get a fermentation_logs portal into my productions form.
My Script linked to Add Transaction looks like this
Do you see any clues?
PS Now every script I write "cannot be found or has been deleted" :/
I am beginning to think I do not even need a button, as the field appears and once I start filling it out a new record appears under it. Was that obvious? I was so stuck on having an add button.
Does the following seem right?
This was using this script in this form: ((Do you see any issues here or any reasons why not to use the "Go to"?
Thanks for being awesome,
If all you want to do is add a new record, then, no, you don't need a script. All you have to do - as you've discovered - is put your cursor in the last (empty) row of the portal and start typing. This will automatically create a new record.
If your portal is not tall enough to show the blank row (and it won't be if there are enough records), then you can add a button that executes a script with the steps you have, only a slight modification:
Go to Field [ item::serial_number ]
Go to Portal Row [ Last ] (don't choose "Select")
This will place the cursor in the last row.
Your Set Field steps are still missing the data - what you want FileMaker to set the field to. I know it's a little confusing to say you use the "Calculation Dialog" to insert a constant, but a constant is a form of calculation in the FileMaker world. (Example: "1" is a text constant you could type in the Calculation Dialog; it always evaluates to the text string, well, "1".) :-)
But if you just want to move to the field, then Set Field isn't what you want. That's for when you want to insert actual data into the field.
As for why it's telling you, "This script cannot be found or has been deleted," it's probably because you never attached a script to the button. You do this by choosing "Perform Script", then clicking "Specify" in the Button Setup dialog:
If there's no script selected, FileMaker will give you that error. (You can get this dialog by double-clicking the button.)
Let me know if you have further difficulties.
I'm having one of those days. I've set up just the sort of script you describe to create a new related record and set a field value. But I can't get that far because the script keeps stopping (exiting) as soon as I get to the New Record/Request step on the main table. I think I must be making some obvious mistake, but I can't see it. The Script Debugger only gets as far as "New Record/Request" then shows no more script steps. I can add the related record manually through a portal, so I believe the relationships are set up correctly. Here's the script, and the place where it stops:
Go to Layout [ “Organization Contact - Detail” (ORGANIZATIONS) ]
***This is as far as the script gets, then it just exits and leaves the cursor in the first field of the above layout. I set the data viewer to show the value of $OrgID (next step below), and it never shows a value.***
Set Variable [ $OrgID; Value:ORGANIZATIONS::_ID ]
Go to Layout [ “ContactsJoin” (ContactsJoin) ]
Set Field [ ContactsJoin::_OrgID ; $OrgID ]
Commit Records/Requests [ No dialog ]
Go to Related Record [ From table: “ORGANIZATIONS” ; Using layout: “Organization Contact - Detail” (ORGANIZATIONS) ]
I checked the script triggers on the main layout and the only one is OnLayoutEnter (resize/refresh). No other script triggers that could be interfering. I also had problems today with a script to show my own custom dialog, and no beep, when Get(FoundCount) = 0, and that also didn't doing anything. I'm beginning to worry there's something wrong with FM13 or with my file. I'm a newbie, in-house staff at a nonprofit, so I could just be missing something obvious. Any idea what's going on?
What error code does the debugger report when it attempts to execute the New Record / Request step?
There's no error. It simply creates the new record (in the parent layout as specified) and then happily stops there with the cursor blinking, like its work is done. It's as if the rest of the script doesn't exist (yes, I saved it!). The Script Debugger goes blank and no value appears for $OrgID in the Data Viewer.
Can you attach a copy of the file?
Your script is setting $OrgID to the value of the _ID field on the new record. Presumably, that field auto-enters a serial number. Perhaps it's set to generate the number on commit rather than on creation? Try adding a commit script step before the set $OrgID.
Is it possible you accidentally disabled those script steps?
Good suggestions. No, I didn't disable any script steps. I tried adding a commit script step, but it didn't fix the problem. I've scaled down the copy to just the bit I'm struggling with and am trying to figure out how to ZIP it to send. One minute!
Okay, here's the stripped down version. The script is "New Organization" and it's called from the "Add New Contact" button and then "New Organization" button on the popover, both on the "Organization Contact - Detail" layout.
It works normally here when I execute it from the Scripts menu. I don't have 13 yet (and therefore can't test the popover), but there may be an issue with layout elements.
But the script works okay on my Mac. You might have an issue either with your machine, or your copy of FileMaker, or with the layout element.
Wow, this is one of those embarrassing moments. It worked from my Scripts menu too, so I tried moving the button off the popover, no better, then I checked the button setup and discovered that I'd set it to create a new record instead of to run the script. I'm not that familiar with the Debugger and didn't realize it wasn't even running the script. Well, thanks so much for taking the time to look, and this just reinforces that it's usually human error, isn't it? Thanks again!
I may have found the problem. The New Organisation button on the popover doesn't call the script at all. Instead it calls the single New Record/Request step. This is consistent with the behaviour you describe. The script itself works fine in FM13, by the way. Change the button to call the script and you'll be up and running.
Retrieving data ...