radiodan Posted March 19, 2007 Posted March 19, 2007 I am trying to write a script to check for a word in a field, and perform a task if it exists. The field contains several words from a value list, for example days of the week, these are selected by check boxes. So the field might contain Monday, Wednesday, and Friday, or Tuesday, Friday or Friday, Monday (no particular order). I want the script to run if it sees the word Wednesday else end. If I use the script step IF Days = "Wednesday" this only works if only Wednesday is in the field. So I guess I want the script step to do the same as a find (without the = sign). There is probably a really simple answer but spending ages on the forums hasn't revealed it. Any help much appreciated.
Fenton Posted March 19, 2007 Posted March 19, 2007 (edited) [P.S. The checkbox field must have ONLY "Wednesday" on a line for the below to work. If you have other stuff on the line also, then it won't.] A checkbox field stores its values as return-separated text. A relational key sees each of return-separated values. So a relationship and a checkbox field are a better fit for matching than a Find. However, you would need something that had "Wednesday" in it on the anchor side of the relationship (with the checkbox field on the target side). This could be a global field, with the days of week as the value list, either checkbox or radio button (depending if you want multiple or only one choice). Or, if you're using a script, and if ONLY Wednesday is the day, then create an calculation field, result "Text", Storage [x] "Do not store", with the calculation being simply: "Wednesday" If the relationship from the above field to your checkbox field is not empty, then go to those records and do whatever. Go to Layout [ layout of table where Wed. calculation field was defined ]* If [ not IsEmpty ( Wednesday Relationship::Checkbox field ) ] Go To Related Record [ Wednesday Relationship; Show only related, current record ]** Do whatever else End If * Could be any table, in theory, but often the same as the checkbox field. The calculation field does NOT have to BE on the layout; that's irrelevant; nor the checkbox field for that matter. ** Could be any layout of the table where the checkbox field was defined; even if the target layout is not "attached" to the relationship in any way; i.e., not in the same table occurrence group (no continuous line to it from your anchor). Don't worry, FileMaker will show you the possible layouts. Edited March 19, 2007 by Guest
radiodan Posted March 20, 2007 Author Posted March 20, 2007 Hi Fenton, Thanks for the response, what you suggest would work for my display purposes, but I think might be to complicated to implement in the script. I use a script to generate an HTML email at the moment it says if Monday = Monday then get all the information for Monday. The fields in reality hold all of our job types, so when we update a customer the email only includes information for relevant products. The problem is that every time we add a new product I have to create a new field and value list for that product. It would be much simpler to have one field called JobTypes and then append a value list. But as there seems no way of asking Filemaker in a script if a check box field contains one of a number of values, I'll have to stick to the current way. Which isn't a big problem, just not very elegant! Thanks for your help Daniel
comment Posted March 20, 2007 Posted March 20, 2007 there seems no way of asking Filemaker in a script if a check box field contains one of a number of values Try: If [ not IsEmpty ( FilterValues ( "yourValue" ; yourCheckboxField ) ) ]
radiodan Posted March 20, 2007 Author Posted March 20, 2007 (edited) Hi guys, I was probably to vague; the script sets all my variables from the table and then produces the email body field with a calculation. The suggestions doesn't work. Blow is an example, am I doing something wrong? If (not IsEmpty ( FilterValues (Campaign Project::Components; "Prize")); TextStyleAdd ( $PrizeHead ; 256 ) & TextStyleRemove ( "" ; 256 ) & "¶" & Case ($PrzName =""; TextColor ("¶PRIZE NAME: " ;RGB (255;0;0)) & TextStyleRemove ( "" ; 256 ); "¶PRIZE NAME: " & $PrzName) & Case ($PrzDesc =""; TextColor ("¶PRIZE DESCRIPTION: " ;RGB (255;0;0)) & TextStyleRemove ( "" ; 256 ); "¶PRIZE DESCRIPTION: " & $PrzDesc)) Edited March 20, 2007 by Guest
comment Posted March 20, 2007 Posted March 20, 2007 For one thing, your original question was about a script - now you are showing us a calculation. For another, "doesn't work" is not a good description of a problem.
radiodan Posted March 20, 2007 Author Posted March 20, 2007 My mistake, that calculation is the final part of a script (I really should have been more accurate). When I say it doesn't work what I mean is: that part of the calculation should result in the text in the calculation being part of the resulting field, it does not. Previously I used the below calculation on a field that contained a single value. Perhaps I should use the not Is Value script step to set a variable and query then string as below. I will give that a go. again apologies for not being clear. Daniel If ($Prize = "Prize"; TextStyleAdd ( $PrizeHead ; 256 ) & TextStyleRemove ( "" ; 256 ) & "¶" & Case ($PrzName =""; TextColor ("¶PRIZE NAME: " ;RGB (255;0;0)) & TextStyleRemove ( "" ; 256 ); "¶PRIZE NAME: " & $PrzName) & Case ($PrzDesc =""; TextColor ("¶PRIZE DESCRIPTION: " ;RGB (255;0;0)) & TextStyleRemove ( "" ; 256 ); "¶PRIZE DESCRIPTION: " & $PrzDesc))
comment Posted March 20, 2007 Posted March 20, 2007 I am getting more and more confused here. First you said you are "trying to write a script to check for a word in a field, and perform a task if it exists." For this, your script would look something like this: If [ not IsEmpty ( FilterValues ( "yourValue" ; yourCheckboxField ) ) ] # PERFORM A TASK HERE End If To carry out the same test in a calculation: Case ( not IsEmpty ( FilterValues ( "yourValue" ; yourCheckboxField ) ) ; <> ) I am not familiar with "the not Is Value script step".
radiodan Posted March 20, 2007 Author Posted March 20, 2007 As you say I got myself quite confused over this (I'll try to be more clear next time). Your solutions both work for me now depending on how I implement them, the second suggestions is ideal. I had never used FilterValues in a calculation before I can now see a number of applications for it. Thanks for your help Daniel
comment Posted March 20, 2007 Posted March 20, 2007 depending on how I implement them That is always true. ;)
Recommended Posts
This topic is 6459 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 accountSign in
Already have an account? Sign in here.
Sign In Now