fredley Posted May 1, 2005 Posted May 1, 2005 Hi, can you help me I am creating a script that will be activated when a field specified as a button is clicked. When this script is performed, it makes use of the Get(ActiveFieldContents)function, by setting other (global) fields to the value of the clicked field, and finding records with criteria in the clicked field. However I cannot seem to get it to work. The first thing the script does is: (to prevent the script from continuing if the target field is empty) If(Get(ActiveFieldContents) = "" Show Custom Message "Please select a field" Exit Script End If And this always results in the message being displayed. Another test I have done is simply defining a calculation field as Get(ActiveFieldContents) and placing it in a layout I use for data entry. Selecting different fields in browse mode and entering data seems to have no effect, the field always stays blank. What am I doing wrong? Can Anybody guess why the Get(ActiveFieldContents) doesnt seem to work? Many Thanks Fred
comment Posted May 1, 2005 Posted May 1, 2005 Get(ActiveFieldContents) does work. However, it will not work for what you want. In your first example, if the field is defined as a button, clicking on it will activate the script, not the field. You could start the script by Go To Field [ thisField] to activate the field, but then you would have to specify the field by name, and I guess that would defeat your purpose. In your second example, when you click into the field, Get(ActiveFieldContents) gets the field's contents. But, for as long as your cursor remains in the field, the screen is not refreshed, so your calculation field remains empty. When you do click outside the field, the screen is refreshed - but at this time no field is active anymore. Try this to see how it works: - Define a global text field gActive - Add a button to the layout with the action: Set Field [ gActive ; Get(ActiveFieldContents) ] - Click inside any field, then click the button.
fredley Posted May 1, 2005 Author Posted May 1, 2005 Can you suggest any way round the problem? What I have is a long list of global text fields, and on click one of these texts fields, or by other means, I want to be able to search for fields containing criteria defined by the text field clicked. I can do this one by one with individual scripts, but as I have over 50 fields this is tedious. I will continue fiddling...
fredley Posted May 1, 2005 Author Posted May 1, 2005 OK, think I have sorted, Have the fields want defined as records in another file. Then that field set as value set in that file, then import value set into main file. Simple scripting from then on. One question though Is it possible for search criteria to be another field?
Fenton Posted May 1, 2005 Posted May 1, 2005 Some "status" (now "get") functions, such as Get (ActiveFieldContents) are not meant to be seen in Browse mode, only to be used in calculations and scripts. I guess because they can't evaluate in order to show. In the case where you're clicking on different fields, but want them to run a common script, I would use the new Script Parameter option, which you assign for each "button" attachment; it's at the bottom of the dialog. Just specify the field that it's attached to, and it will send the contents of that field. Use Get ( ScriptParameter ) to retrieve the value in your script. If [ IsEmpty ( Get ( ScriptParameter ) ) Show Custom Dialog [ "Field is Empty" ] Exit Script End If If you want to go to the field, in order to do a Find, or for any reason, you're going to have some problems. There is no Go To Field [ by calculated name ].* Further, by attaching a button to the field, it becomes impossible to get Active Field Contents or Name; because you're never actually in the field. And you can't Go To Field [ that field ] for this same reason. Catch 22 (old). It would be possible to set both the field AND its name (as hard-coded text) into the Script Parameter, as 2 separate lines, then parsing both out again (don't forget to remove the silly extra GoToField.zip
Raybaudi Posted May 1, 2005 Posted May 1, 2005 Hi to all I think that what I serched for isn't possible... It seems related to this topic. How can I retrive the name of a field, based on a string ? ( GetFieldName(text) ) So, if I have 2 fields: Field1="Apple", Field2="Banana" the result of GetFieldName("Apple") will be: Field1 :
fredley Posted May 1, 2005 Author Posted May 1, 2005 Thankyou, using scriptparameter works brilliantly, although I still do need to set it manually for each field, it is still much much quicker.
Fenton Posted May 1, 2005 Posted May 1, 2005 If you look at my script you'll see that I hard-coded the field name into the script parameter. Then I had to Loop through the fields on the layout (where it is possible to Get (ActiveFieldName) ), until one of them matched (hopefully). That's the method, primitive but effective. You could do similar with Get (ActiveFieldContents), Looping though the fields, comparing the current field contents against a preset string value. If that's what you mean by "retrieve the name of a field based on a string"; do you mean "the name of the field who's contents are the string"? Tip: Commit Records/Requests removes the cursor from the Tab Order, then Go To Next Field will begin at the 1st field. You must trap so people do not get stuck in an endless Loop, if what is specified is not on the layout. I'm not at all sure what you're trying to do. I'm just guessing.
comment Posted May 1, 2005 Posted May 1, 2005 I believe you are on the right track. Here's a little demo showing how it might be done. findByPortal.fp7.zip
comment Posted May 1, 2005 Posted May 1, 2005 Your question is indeed not clear enough. What are you trying to achieve?
Fenton Posted May 1, 2005 Posted May 1, 2005 Well, comment's file is certainly more sensible, except for :-) "Our elephants enjoy daiquiri."
Raybaudi Posted May 1, 2005 Posted May 1, 2005 Hi, Fenton thank you for your quick replay You know that if I export a file as XML, there I can see the name of a field (of all the fields) and what is inside it... So I serched for a tip to grab that name, not its contents !(but based on its contents)
fredley Posted May 1, 2005 Author Posted May 1, 2005 Please help me, see my topic in the Define Fields Forum, I think I may have to start my entire database again...
comment Posted May 1, 2005 Posted May 1, 2005 You don't know these elephants - they will drink anything.
Raybaudi Posted May 1, 2005 Posted May 1, 2005 Hi, Michael I need the name of a field !! I can't use the normal functions of FM7, or so I think ! I need it for recursively search into a repeating field.
comment Posted May 1, 2005 Posted May 1, 2005 I still don't understand the context. How will you input the field contents? And what will you do with the name of the field, once you get it? IOW, I don't understand what is known and what not. Here's an example that does what you describe - but is it good for anything? GetFieldName.fp7.zip
Raybaudi Posted May 2, 2005 Posted May 2, 2005 Yes, you are right... I can't do anything with the name of a field in a script context. But I think that it's possible to use the name in a custom function... Your attachment does what I wanted, but you had to hard coded the names ! So, if I add a new Field5 with "ananas", and I search for ananas, nothing returns. (I would to add the Field5 !) In the case of a repeating field, I wish to have Field1[5] as the result !!
Søren Dyhr Posted May 2, 2005 Posted May 2, 2005 You shouldn't be chasing this: I need it for recursively search into a repeating field. Since it's not a proper filestructure, such searches went out of fashion in 1995 when filemaker became relational! Repeating fields is for relational keys not for storing data. --sd
comment Posted May 2, 2005 Posted May 2, 2005 I could have used the FieldNames() function - but then I would have to know the layout name. As I said - I don't know what the context is. It seems to me this is a solution looking for a problem.
Raybaudi Posted May 2, 2005 Posted May 2, 2005 Hi Yes, I know... But there are so many people who stored something into so much repeating fields that I wished a function to change a repeating field into a text field: GetRepeatition'sText(repeatingField), without using a Loop for each repeating field in a script.
Raybaudi Posted May 2, 2005 Posted May 2, 2005 Arghhh ! Yes, yes, yes !! It was that "Middle" that makes me a wrong finder ! Thanks for your effort ! Tip1 : Do you knew that you can obtain the MAXREPEAT of a repeating field with: GetAsNumber ( FieldType ( Get ( FileName ) ; "repeatingField") ) ?? Tip2: Do you knew that You can set a "value list" with the values coming from a repeating field :
Søren Dyhr Posted May 2, 2005 Posted May 2, 2005 GetAsNumber ( FieldType ( Get ( FileName ) ; "repeatingField") ) It escapes me where to exploit such knowledge ...could you think up an example?? Drilling people in "nice to know's" serves what purpose exactly?? --sd
Raybaudi Posted May 2, 2005 Posted May 2, 2005 Hi, Soren I can't understand exactly what you said, but it seems to me that you are smiling back to me ?!! If it is so, never mind ! If it is not so, please help me to understand better what you said ! BTW the MiddleRepetitions ( repeatingField ; startRepetition ; endRepetition ) custom function by Comment requests (as I supposed) the endRepetition (or the MAXREPEAT, if you want all the values of the repeating field). This is a good example ?
Søren Dyhr Posted May 3, 2005 Posted May 3, 2005 My point is, why substitute one violation of 1NF with yet another violation? I'm guessing here - but isn't our task as developers to avoid inadequate methods by and large ...if you enherit a solution stuffed to it's burstingpoint with reperaters - must initial work establish what relational structure to pursue to prevent redundance and inconsitency. This means that only vanity prevents you from exploiting scripts to this once and for all task to transform data to fit into a new more reliably structure and wrongly stored information in it's proper place!!! The words for such devotion to repeating fields must be "Byzantine" and "Elaborate" ...and even worse "Stubbornness" ...alright they have their place as keyfield holders if Custom Functions are out of reach!!! --sd
Raybaudi Posted May 3, 2005 Posted May 3, 2005 I do not love "repeating fields". But we are forced to cohabit to them! As I have said to you, some solutions have been developed with this type of field and, in order to convert them with facility, I went trying one solution like that proposed by the friend Comment. After all, these words are not present in the English dictionary of babelfish: 1NF enherit burstingpoint inconsitency stubbornness alright
Søren Dyhr Posted May 4, 2005 Posted May 4, 2005 Ah yes, a few typos, I'm afraid: http://databases.about.com/cs/specificproducts/g/1nf.htm http://www.answers.com/inheritance&r=67 http://www.answers.com/bursting&r=67 http://www.answers.com/inconsistency&r=67 http://www.answers.com/stubbornness&r=67 http://www.answers.com/alright&r=67 Sorry! in order to convert them Why use calc'field in stead of scripted replaces? --sd
Raybaudi Posted May 4, 2005 Posted May 4, 2005 Alright ! finally I have understood to you. The use of the function is more simpler of the script (this is my opinion)! Many thanks for the link to www.answers.com ! Ciao
Søren Dyhr Posted May 4, 2005 Posted May 4, 2005 The use of the function is more simpler of the script Not sure: Loop Exit Loop If [ ValueCount ( Untitled::theRepeat[1] ) = 10 ] Set Field [ Untitled::theRepeat; Untitled::theRepeat & "
comment Posted May 4, 2005 Posted May 4, 2005 I think there may be more than one record... So it's two loops. And each record may contain a different amount of repetitions, so if you don't want to stack carriage returns it should be: Go to Record [ First ] Loop Loop Exit Loop If [ ValueCount ( Target ) = Count ( RepeatingSource ) ] Set Field [ Target ; Target & "
Raybaudi Posted May 4, 2005 Posted May 4, 2005 I agree with Comment. This is the last word for now... may be later...into other topics...
Raybaudi Posted May 4, 2005 Posted May 4, 2005 Hi, Comment You can't use Count(repeatingSource) !! It were be too simple !! You have to use the MAXREPEAT , as definited in other my post. I try to explain: I have a repeatingField of 7 repeatition, but one is empty. Monday Tuesday Thursday Friday Saturday Sunday Your solution gives: Monday Tuesday Thursday Friday Saturday That is wrong ! But: Replace Field Contents [ No dialog ; Target ; MiddleRepetitions ( RepeatingSource ; 1 ; GetAsNumber ( FieldType ( Get ( FileName ) ; "RepeatingSource") ) ] is always correct
Recommended Posts
This topic is 7145 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