Jump to content

This topic is 3131 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Hi all,

Apologies if this in the wrong place, but it seems like the best fit. Just wondering if anyone can help me out with a script I'm struggling with.

The background: I have a button I'm using to launch a new window with another layout, then create a new, related record. This action will only happen if the user has completed a specific field in the original layout (__pkCollectionRef), step one of the script.

With the new window open, the user will then make a selection from a checkbox set and close the window, which will put their selections into a field in the original layout.

This part's all fine. What I want  then, however, is for the button to be made inactive once they've completed their selection, so the script won't run if they press it a second time (this is to prevent the creation of redundant records - there is another button that will allow them to edit their previous selections if required).

I've attached two screen grabs of the script steps. The first is the script I require help with, the second is the script run if the necessary conditions of the first are met (i.e the creation of a related record in a new window and layout).

The _fkPickList field in the original layout will only be populated upon the creation of the new related record, so I had thought that adding the isValid calculation as a means of halting the script would do the trick, however what's happening is that it's preventing the script from running in the first place.

As a side note, I've also added conditional formatting to the button so that when the _fkPickList field isValid the text is greyed out. This one discourages pressing the button a second time, however, not prevent it from working.

Thanks in advance for the help. All comments appreciated.

Franco.

Screen Shot 2015-09-22 at 10.58.05.png

Screen Shot 2015-09-22 at 10.47.07.png

Link to comment
Share on other sites

First two things i would do is change the halt script calls to exit script calls or properly nest the script to eliminate the multiple exit points.

Next thing i would do is leverage the relationship graph and set field to eliminate the need for copy / paste and the switching windows just to create related records.

Safe rule of thumb is to leave the operating systems clipboard alone whenever possible so avoid copy /paste unless its the only way to do what you are trying to do.

When you have create turned on in a relationship you can, under the right conditions, create new records in the child table with set field.

http://filemakerhacks.com/2011/07/31/magic-key-and-check-box-reporting/

 

Edited by Kris M
Link to comment
Share on other sites

Hi Kris,

Thanks for your reply. I've tried replacing halt script with exit but I experience the same problem. The condition based on the validity of the _fkPicklist field is ignored and a second new record created. 

I'm afraid I don't quite follow your suggestion to 'properly nest' the script. Could you expand on that?

Here's a quick vid that shows why I need a new window for a different layout/related record, and how it presently functions. Everything is correct until the last step, when it generates an additional record rather than exit the script. which it should as the _fkPicklist field is populated following the selection process (the field is on the top right but hidden from the user). The reason this is a problem is that each Request form should only have one Picklist form associated with it.

Any thoughts?

Cheers.

 

DB_example.mp4

Edited by FrancoFranco
Problem uploading video file
Link to comment
Share on other sites

My suggestion to change to halt is not really necessary but i don't like leaving a script in an aborted state especially when the script is called from or calls other scripts.

I'd never want to have to troubleshoot a multi script process where halt script controlled the flow instead of other methods. Just me.

Proper nesting means rearranging the sequence of control script step events ( if, else if, end if, loop, end loop) so that their is one and only one exit (stop) condition in a script.

If you do any kind of procedural programming you will know this idea.

Your top script has 3 exit points.. two with halt script and one when the last line is executed.

Some might consider proper nesting premature optimization but its good form/practice until you learn when its ok to break the rule.

You should really take a long look at the magic key technique for creating related records. 

Imagine what happens if you copy to the clipboard and the OS does something to the clipboard just before paste is executed?

i would suggest that you zip and post the file so we can see the relationships, especially the one that is used in the If ( IsValid ( this one )....

 

Edited by Kris M
Link to comment
Share on other sites

Instead of the Copy/Paste, look at passing a script parameter. In the Perform Script step there is an optional "Script Parameter" field at the bottom. Set that to pull the value you were copying orginally. In the Select Items-Foundation Script, use Get ( ScriptParameter ) to pull the value into the script. Use that in either the Set Field script step, or the Set Variable depending on what you are doing with it.

Also, are any of your users on Windows? If yes, I would avoid spawning a new window. Just use Go To Layout to jump over and back. However, the "MagicKey" technique is my preferred method of creating related records in most circumstances, for a variety of reasons.

Link to comment
Share on other sites

 

Proper nesting means rearranging the sequence of control script step events ( if, else if, end if, loop, end loop) so that their is one and only one exit (stop) condition in a script.

If you do any kind of procedural programming you will know this idea.

Your top script has 3 exit points.. two with halt script and one when the last line is executed.

Some might consider proper nesting premature optimization but its good form/practice until you learn when its ok to break the rule.

 

Sorry, Kris, can you give an example of how my script should look when properly nested? My own efforts to rectify the problem included the else and else if commands, but I was always returned an error message when I tried to save, so clearly I failed to grasp the proper use of these...

I take your and Josh's point re the copying/pasting of data between layouts and will look into improving this process, however while I agree it's not optimal, it does achieve my end goal and I don't believe it's an element of the scripting problem I'm dealing with.

All Mac users, Josh, and its an internal office database so no chance of it getting into the wild and mating with Windows.

Thanks guys.

Link to comment
Share on other sites

There are a few options with FM 11, if that is what you are using, if you want to hide the button ( a single row portal that only holds your button, and you just set a field to show/hide the field ). You can also trap for conditions to decide if you are going to run the rest of the script or not.

It kind of looks like you are already doing that. So it's hard to tell what the problem is. You need to see if your script is seeing the correct value in your 2nd If test.

Link to comment
Share on other sites

You can also trap for conditions to decide if you are going to run the rest of the script or not.

It kind of looks like you are already doing that. So it's hard to tell what the problem is. You need to see if your script is seeing the correct value in your 2nd If test.

Yes, this is what I'm trying to achieve. But for some reason it doesn't seem to go through the checks correctly. Check one works okay, aborting if the user hasn't selected a Collection, but when it gets to check two, the isValid command for _fkPicklist, even if this is an empty field it still halts the process, rather than seeing it as false and running the script as desired.

Here's a duplicate of the DB I'm working on. You can test out the function by making a new request on the Request Items layout. The script in question is Select Items-Run...

Collections Database.fp7

Link to comment
Share on other sites

I would go with something more along these lines to get the dialog popup out of the way. I try to avoid intrusive dialogs whenever possible.

One drawback to this approach is that it uses a Global Variable. To use it, you have to work around cleaning it up and only displaying it when you want it to show. And make sure you update it as needed. It can be messy, and I don't normally go this route. But I wanted to just show you the script running.

I also dropped the script trigger you had on that one field as it seems to interfere with data entry, and doesn't do anything except move you to the next field. If you need a trigger there, you need to trap for whether or not the script is running so that you don't undo the behavior the script is giving you.

 

Collections Database.fp7

Link to comment
Share on other sites

Not sure if this will solve your issue, but IsValid is not a reliable way to test for the existence of related records. IsEmpty is the function you want, e.g. "not IsEmpty( related::field )" tells you whether the related record exists. This has been discussed at length over the years.

Link to comment
Share on other sites

This topic is 3131 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.