innodes Posted June 13, 2008 Posted June 13, 2008 Is there a way to clear all globals in a table? I have a table that contains all of my global variables. I would like to be able to use a script that would clear them all out as the first step. I have tried: Show All Records Delete All Records but the nothing was cleared. I know that this works: Set Field [GLOBALS::color_g;""] Set Field [GLOBALS::type_g;""] etc. etc. but I have so many, it would be nice to have a cleaner way. I have searched the forum, but not found an answer that worked. thanks
Raybaudi Posted June 13, 2008 Posted June 13, 2008 Hi This script may work, but you have to perform it while in a layout showing all ( and alone ) your global fields. Set Variable [ $count ; Value: ValueCount ( FieldNames ( Get ( FileName ) ; Get ( LayoutName ) ) ) ] Loop Exit Loop If [ not $count ] Go to next field Set Field [ [color:red]<> ; "" ] Set Variable [ $count ; Value: $count - 1 ] End Loop Commit Records/Requests [ ]
Fitch Posted June 13, 2008 Posted June 13, 2008 As you discovered, global field values are retained even when you delete all records. Saving a clone however, will clear them out. One advantage of global variables is they all disappear when the file closes.
mr_vodka Posted June 13, 2008 Posted June 13, 2008 Try this... http://fmforums.com/forum/showpost.php?post/179234/
innodes Posted June 17, 2008 Author Posted June 17, 2008 (edited) Thank you one and all. Daniele, Thanks, I will try it. Where you have the <>, do I just leave that blank? John, I see from your file it works, but how? What is it doing? How is it clearing the globals? I like it and looked at the scripts, but don't understand how you did it. - I did some more digging and see it is through an auto-calc. Pretty clever. Thanks. Some of my globals are created with auto-calcs and look-ups from other fields. I will have to see if I can make this work in combination with them. Fitch, I have various relational links that the globals are using. From what I was able to read, the variable rout wasn't recommened. But from what you are saying, I could have just created a "$$colors" instead of setting up the "colors" field in the globals table. Is that right? I will have to play with that. It sounds much simpler. But, then how would I clean it out? Perhaps using the "$colors"? Again from reading it looks like that would clean itself out as soon as the script is finished. Is that right? That might do the trick also. thanks again to all! Edited June 17, 2008 by Guest updated
Raybaudi Posted June 17, 2008 Posted June 17, 2008 Where you have the <>, do I just leave that blank? Yes.
Fitch Posted June 17, 2008 Posted June 17, 2008 Global fields can do several things that global variables can't, including: - display on a layout - drive a relationship - access from other files You could use $$colors. It would clean itself up by disappearing when you close the file. I'm not sure how you envision using script variables, but yes, they disappear once the script has completed. Another note about defining variables: you can use a Let function to set/clear a group of variables, which may be easier to manage. E.g. Set Variable( $x ; Let( [ $$color = "red" ; $$color[2] = "white" ; $$color[3] = "blue" ; $$etc = "ok" ] ; "" ) )
Recommended Posts
This topic is 6001 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