Jump to content
The ORIGINAL FileMaker Community - Forum - Online Business Apps & Software Forum

Recommended Posts

James56

Hi. Thanks for any help you can give in advance.

I have a text field that can contain the following:

P

X

or be empty.

Instead of using a pop up or drop down list I'd like to script it so when I click on the empty field it changes to P. If the P is already there clicking on it will change it to X. Clicking on the X will empty the field. I'm thinking a script trigger using On Record Load. I stumbled on a way to script the entering a P then clicking on it to make it an X but after that I was lost. I scrubbed that and now can't even get that to work! Another reason to back up even poor work I suppose.

Any thoughts, anyone?

Thanks,

Jim

Share this post


Link to post
Share on other sites
David Head

I like this kind of thinking to make the user task easier and consistent when entering data. It is all about efficiency.

 

Create the script to do the task:

 

Set Field - P X empty

 

#cycle through empty, P, X, empty...

 

If [ IsEmpty ( Test::textfield ) ]

Set Field [ Test::textfield; "P" ]

Else If [ Test::textfield = "P" ]

Set Field [ Test::textfield; "X" ]

Else

Set Field [ Test::textfield; "" ]

End If

 

Then make the field a button that runs the script. The script runs when the user clicks on the field.

 

Simple?

 

For a more portable solution, you could pass parameters to the script being the field name and the list of values to use. Then the script could potentially be attached to any field with any list of values. There's a challenge for you ;)

Share this post


Link to post
Share on other sites
James56

David,

Thank you. This is what I was looking for. I will be making a change similar to what you mention but using script parameter to apply it to several fields. Would making the field a button be more functional or efficient than a script trigger?

Thanks again,

Jim

Share this post


Link to post
Share on other sites
David Head

If you make the field a button, there is no need for the user to enter the field. So yes I think it more efficient than a script trigger on the field.

 

FWIW, making a field a button is a script trigger by another name ;)

Buttons were the script triggers we had before we had script triggers!

Share this post


Link to post
Share on other sites
James56

David,

I created the script first using the actual field name and it works flawlessly! But when I try to use the Get (ScriptParameter) function it halts after entering the "P".

Here's what I did.

If [isEmpty (Get (ScriptParameter))]

 

Set Field [(Get (ScriptParameter)= "P"]

Else if [(Get (ScriptParameter)= "P"]

Set Field [(Get (ScriptParameter)= "X"]

Else

Set Field [(Get (ScriptParameter)= ""]

End If

Help!

Thanks,

Jim

Edited by James56

Share this post


Link to post
Share on other sites
James56

David,

I edited my last reply and I'm now realizing that I probably should have made another post instead so you would be sure to see it!

Thanks,

Jim

Share this post


Link to post
Share on other sites
David Head

You need to use the Set Field by Name script step and specify Get ( ScriptParameter ) as the field.

Set Field by Name [ Get ( ScriptParameter ) ; "P" ]

 

The field will need fully qualified. If hard coded, it needs to be passed in quotes -- "Tablename::Fieldname".

 

The If tests will also change:

 

If [ IsEmpty ( Evaluate ( Get ( ScriptParameter ) ) ) ]

and

Else If [ Evaluate ( Get ( ScriptParameter ) ) = "P" ]

 

FWIW, I tend to unpack script parameters into variables.

In this case there is only one but that may change ;) It would be easy to also pass the list of values for setting the field.

 

So use Set Variable steps at the start:

Set Variable [ $field; Get ( ScriptParameter ) ]

Set Variable [ $fieldvalue; Evaluate ( $field ) ]

 

Then you can use $field in the Set Field by Name steps:

Set Field by Name [ $field ; "P" ]

 

and the If tests become:

 

If [ IsEmpty ( $fieldvalue ) ]

and

Else If [ $fieldvalue = "P" ]

Share this post


Link to post
Share on other sites
James56

David,

Still struggling. I think the variable route would make the most sense but I just can't get it to work. Here is my script:

 

SET Variable [ $days; Value;Get (ScriptParameter)]

SET Variable [ $dayvalue; Value:Evaluate ($days)]

IF [isEmpty ($dayvalue)]

SET Field by Name [$days;"P"]

ELSE If [ $dayvalue = "P"]

SET Field by Name [$days;"X"]

Else

SET Field by Name [$days;""]

End If

 

The passed scriptparameter is day1 or day2 or day3

 

What am I doing wrong? Also, you gave me 2 ways of doing this. One not using variables but you state that the "field will need to be fully qualitified. If hard coded, it needs to be passed in quotes -- "Tablename::Fieldname". Does this mean when I pass the scriptparameter instead of putting "day1" I need to put in "Students::day1" ?

Thanks for your help and patience.

Jim

Share this post


Link to post
Share on other sites
David Head

Yes the script parameter will need to be something like "Students::day1".

If you are passing just "day1" then there would be a field not found error occurring.

Do you have FileMaker Pro Advanced to run the script debugger and see what is going on?

Share this post


Link to post
Share on other sites
James56

David,

Sorry for not replying in a timely manner. I had a minor family emergency that took me out of town rather unexpectedly. But I'm back and applied the change (including and then enclosing the entire Table Name:: Field Name in quotes) and it works perfectly! I couldn't ask for a more elegant solution to my problem and it taught me something (actually a few things) in the process.

And yes, I do have Advanced Pro. The debugger was saying the "field not found" so that had me scratching my head.

Thanks again,

Jim

Share this post


Link to post
Share on other sites
James56

David,

Thought you'd like to know that I've applied this technique to 2 other areas of my solution. I think I'll find a couple more before I'm through that will make my life easier too.

Thanks again,

Jim

Share this post


Link to post
Share on other sites
David Head

Elegant solutions and teaching something -- that's what I do ;) It makes me happy :D

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.



×
×
  • Create New...

Important Information

Terms of Use