I have a portal in which I’ve place a button with a single step: Duplicate Record. It works, but it always makes TWO duplicates, rather than just one. How do I limit it to one duplicate, rather than two?
There's no way the first script can do anything but exit when step 2 of the second script trips it's trigger.
Do you have advanced? I'd watch this all happen in the debugger to see what's going on.
Hmm, but try making it:
Exit Script [False]
If an event trips a "before the event" trigger, Exit Script [false] will keep that event from being acted on after the script exits.
Is it possible you are double clicking the button and thus running the script twice?
No, I’m not double clicking. To be specific, I put the button in the portal row itself, and it’s set as a single-step button.
can you upload a demo file that illustrates the issue?
When I tested this, it worked perfectly for me using FMP 16 and Windows 10.
I can, but first let me ask you, would you be able to put a script on the portal that is triggered on exit? I find that no matter what I put on the portal it will perform the duplicate record twice. In my database in question, the second command creates a new portal row. In the demo I’m working on, it makes an extra new record in the layout, not the portal. The script step could be as simple refresh window. Just the fact that there’s a separate, unrelated script triggered on exit causes the duplicate record to be triggered twice.
I’ll get a demo file up in a bit, sorry for the lag.
If you have triggers on the portal, that would likely explain the issue as the duplicate record step would trip those triggers. To keep a script's actions from tripping script triggers, I use the following method:
In the script that might trip triggers, add this step before the first such step is executed:
Set Variable [$$TriggersOff ; Value: True ]
In the same script, I include
Set Variable [$$TriggersOff ; Value: ""]
Just in front of any point where the script exits or halts so that this variable is not left with the value True.
In scripts performed by triggers, I put this at the start:
If [$$TriggersOff ]
Well, that didn’t work exactly, but when I tried Halt Script rather than Exit Script, it worked a charm. Thanks so much!
Ugh, except it makes an ugly loop, and I have to force-quit FMP.
Share some details. I use this all the time specifically to avoid the looping that happens when a script trips its own trigger.
Here’s exactly what I have in the script that’s causing the double trigger. You didn’t specify anything for the text result section, so I left it blank. This is at the top of the <trigger on exit> script, that’s creating the doubling up of the duplicate record:
And here’s the duplicate record script that’s being doubled up:
Thanks, I’ll be back to this conversation tomorrow. It’s still not working, and I suspect your answer is correct, but that I must have another script getting triggered somewhere. Yes, I have advanced and will dive into it later. I appreciate you pointing me in the right direction. I’ll report back with what I find.
Got it sorted, the issue was mostly error on my part, getting a bit confused about changes I had made to the original layout and my test layout. The addition of FALSE in the exit script step did the trick.
Thank you SO much!
The difference between Halt Script and Exit Script is that while Exit acts only on the script it is part of, Halt stops any script that is currently running. If this left you in some odd loop it certainly reinforces the possibility that there were other scripts being triggered in the normal course of events. Anyhow, it seems you've sorted the problem out, so I guess all is well. I trust you now know what is going on better than you did before. If not, make sure you delve until you do understand—that is one of the best ways of learning.
Retrieving data ...