Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×
The Claris Museum: The Vault of FileMaker Antiquities at Claris Engage 2025! ×

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

Recommended Posts

Posted

In a multi file solution what would be a good method to use SM on the opening file to register a function with a few declared variables - so that in a subordinate file that value can be recalled? So as not having to pass globals thru a relationship?

Thanks.

Posted

I haven't tried it for that purpose, but there are Java method in the System class called getProperty and setProperty. You could write a pair of functions like this:

System.setProperty( varName, valueToStore );

and

return System.getProperty( varName )

Posted

Thanks Jesse

I ended up with"




RegisterGroovy( "SetProp (varName ; varValue)" ; "System.setProperty( varName, varValue);" ) &



RegisterGroovy( "GetProp (varName)" ; "return System.getProperty(varName);" )&

is there any caveats - like name spacing I should consider when naming my varName so as not to step on any official system variables?

Posted

It's unlikely that you'd step on any system variables. If you're curious, here is a list. If any of these look useful, you can use System.getProperty( "whatever" ) to get the value:


java.runtime.name = Java™ 2 Runtime Environment, Standard Edition

sun.boot.library.path = /System/Library/Frameworks/JavaVM.framework/Versions/1.4.2/Libraries

java.vm.version = 1.4.2-66

awt.nativeDoubleBuffering = true

gopherProxySet = false

java.vm.vendor = "Apple Computer, Inc."

java.vendor.url = http://apple.com/

path.separator = :

java.vm.name = Java HotSpot™ Client VM

file.encoding.pkg = sun.io

user.country = US

sun.os.patch.level = unknown

java.vm.specification.name = Java Virtual Machine Specification

user.dir = /Users/jesse/VersionControl/JaCK3/trunk

java.runtime.version = 1.4.2_09-239

java.awt.graphicsenv = apple.awt.CGraphicsEnvironment

java.endorsed.dirs = /System/Library/Frameworks/JavaVM.framework/Versions/1.4.2/Home/lib/endorsed

os.arch = i386

java.io.tmpdir = /tmp

line.separator = n

java.vm.specification.vendor = Sun Microsystems Inc.

os.name = Mac OS X

sun.java2d.fontpath = 

java.library.path = /Applications/IntelliJ IDEA 5.1.2.app/Contents/Resources/Java:/System/Library/PrivateFrameworks/JavaApplicationLauncher.framework/Resources:.:/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java

java.specification.name = Java Platform API Specification

java.class.version = 48.0

java.util.prefs.PreferencesFactory = java.util.prefs.MacOSXPreferencesFactory

os.version = 10.4.8

user.home = /Users/jesse

user.timezone = 

java.awt.printerjob = apple.awt.CPrinterJob

file.encoding = MacRoman

java.specification.version = 1.4

java.class.path = /System/Library/Frameworks/JavaVM.framework/Versions/1.4.2/Classes/dt.jar:/System/Library/Frameworks/JavaVM.framework/Versions/1.4.2/Home/lib/jaws.jar:/System/Library/Frameworks/JavaVM.framework/Versions/1.4.2/Classes/jce.jar:/System/Library/Frameworks/JavaVM.framework/Versions/1.4.2/Home/lib/netscape.jar:/System/Library/Frameworks/JavaVM.framework/Versions/1.4.2/Classes/charsets.jar:/System/Library/Frameworks/JavaVM.framework/Versions/1.4.2/Classes/classes.jar:/System/Library/Frameworks/JavaVM.framework/Versions/1.4.2/Classes/jsse.jar:/System/Library/Frameworks/JavaVM.framework/Versions/1.4.2/Classes/laf.jar:/System/Library/Frameworks/JavaVM.framework/Versions/1.4.2/Classes/sunrsasign.jar:/System/Library/Frameworks/JavaVM.framework/Versions/1.4.2/Classes/ui.jar:/System/Library/Frameworks/JavaVM.framework/Versions/1.4.2/Home/lib/ext/apple_provider.jar:/System/Library/Frameworks/JavaVM.framework/Versions/1.4.2/Home/lib/ext/ldapsec.jar:/System/Library/Frameworks/JavaVM.framework/Versions/1.4.2/Home/lib/ext/localedata.jar:/System/Library/Frameworks/JavaVM.framework/Versions/1.4.2/Home/lib/ext/sunjce_provider.jar:/Users/jesse/VersionControl/JaCK3/trunk/JaCK_development/test_classes:/Users/jesse/VersionControl/JaCK3/trunk/JaCK_development/classes:/Users/jesse/VersionControl/JaCK3/trunk/JaCK_deployment/test_classes:/Users/jesse/VersionControl/JaCK3/trunk/JaCK_deployment/classes:/Applications/IntelliJ IDEA 5.1.2.app/lib/junit.jar:/Users/jesse/VersionControl/LicenseTools/LicenseClient/classes:/Applications/IntelliJ IDEA 5.1.2.app/lib/ant/lib/ant.jar:/Users/jesse/VersionControl/ProscBundle/ProscFramework.framework/test_classes:/Users/jesse/VersionControl/ProscBundle/ProscFramework.framework/Resources/Java:/System/Library/Frameworks/JavaDirectToWeb.framework/Versions/A/Resources/Java/javadirecttoweb.jar:/System/Library/Frameworks/JavaDTWGeneration.framework/Resources/Java/javadtwgeneration.jar:/System/Library/Frameworks/JavaEOAccess.framework/Versions/A/Resources/Java/javaeoaccess.jar:/System/Library/Frameworks/JavaEOControl.framework/Versions/A/Resources/Java/javaeocontrol.jar:/System/Library/Frameworks/JavaEOProject.framework/Resources/Java/javaeoproject.jar:/System/Library/Frameworks/JavaFoundation.framework/Versions/A/Resources/Java/javafoundation.jar:/System/Library/Frameworks/JavaJDBCAdaptor.framework/Resources/Java/javajdbcadaptor.jar:/System/Library/Frameworks/JavaWebObjects.framework/Resources/Java/javawebobjects.jar:/System/Library/Frameworks/JavaWOExtensions.framework/Versions/A/Resources/Java/JavaWOExtensions.jar:/System/Library/Frameworks/JavaXML.framework/Resources/Java/javaxml.jar:/Users/jesse/VersionControl/ProscBundle/ProscFramework.framework/jars_development/ant.jar:/Users/jesse/VersionControl/ProscBundle/ProscFramework.framework/jars_development/iText.jar:/Users/jesse/VersionControl/ProscBundle/ProscFramework.framework/jars/activation.jar:/Users/jesse/VersionControl/ProscBundle/ProscFramework.framework/jars/junit.jar:/System/Library/Java:/Users/jesse/VersionControl/ProscBundle/ProscFramework.framework/jars/jdom.jar:/Users/jesse/VersionControl/ProscBundle/ProscFramework.framework/jars/mail.jar:/Users/jesse/VersionControl/JaCK3/trunk/Plugins/Diff/test_classes:/Users/jesse/VersionControl/JaCK3/trunk/Plugins/Diff/classes:/Users/jesse/VersionControl/JaCK3/trunk/Plugins/ChartPlugin/test_classes:/Users/jesse/VersionControl/JaCK3/trunk/Plugins/ChartPlugin/classes:/Users/jesse/VersionControl/JaCK3/trunk/Plugins/ChartPlugin/lib/jfreechart-1.0.1.jar:/Users/jesse/VersionControl/JaCK3/trunk/Plugins/ChartPlugin/lib/jcommon-1.0.0.jar:/Applications/IntelliJ IDEA 5.1.2.app/lib/idea_rt.jar

user.name = jesse

java.vm.specification.version = 1.0

java.home = /System/Library/Frameworks/JavaVM.framework/Versions/1.4.2/Home

sun.arch.data.model = 32

user.language = en

java.specification.vendor = Sun Microsystems Inc.

awt.toolkit = apple.awt.CToolkit

java.vm.info = mixed mode

java.version = 1.4.2_09

java.ext.dirs = /Library/Java/Extensions:/System/Library/Java/Extensions:/System/Library/Frameworks/JavaVM.framework/Versions/1.4.2/Home/lib/ext

sun.boot.class.path = /System/Library/Frameworks/JavaVM.framework/Versions/1.4.2/Classes/classes.jar:/System/Library/Frameworks/JavaVM.framework/Versions/1.4.2/Classes/ui.jar:/System/Library/Frameworks/JavaVM.framework/Versions/1.4.2/Classes/laf.jar:/System/Library/Frameworks/JavaVM.framework/Versions/1.4.2/Classes/sunrsasign.jar:/System/Library/Frameworks/JavaVM.framework/Versions/1.4.2/Classes/jsse.jar:/System/Library/Frameworks/JavaVM.framework/Versions/1.4.2/Classes/jce.jar:/System/Library/Frameworks/JavaVM.framework/Versions/1.4.2/Classes/charsets.jar

java.vendor = Apple Computer, Inc.

file.separator = /

java.vendor.url.bug = http://developer.apple.com/java/

sun.io.unicode.encoding = UnicodeLittle

sun.cpu.endian = little

mrj.version = 239

sun.cpu.isalist = 

Posted

Had been struggling to try and adapt Todd Geists video on Expando to do the same thing, but hadn't though of the fact that there is already an object to do this.

Works a treat....

You can also SAVE the last known state of properties so that they become sort of persistant, or able to store all kinds of last know states without using global fields.

According to the Oracle website

'The following example writes out the application properties from the previous example using Properties.store. The default properties don't need to be saved each time because they never change.'

FileOutputStream out = new FileOutputStream("appProperties");

applicationProps.store(out, "---No Comment---");

out.close();




'The store method needs a stream to write to, as well as a string that it uses as a comment at the top of the output.'





Then to read them in ...


// create and load default properties



Properties defaultProps = new Properties();

FileInputStream in = new FileInputStream("defaultProperties");

defaultProps.load(in);

in.close();



// create application properties with default



Properties applicationProps = new Properties(defaultProps);



// now load properties from last invocation



in = new FileInputStream("appProperties");

applicationProps.load(in);

in.close();

Posted

Just been off and looked at this in a bit more detail.

You can save Properties to a file, which clearly you can store inside FM if you wish.. and name will do

For Property think GlobalVariable, for name think $$$var

Then to load it

pp = new Properties()

ff = 'filename'

exists = (new File(ff)).exists()

if (exists){

saved = new FileInputStream(ff)

} else {

return false

}

pp.load(saved)




To save your Properties


fs = new FileOutputStream('filename')

//jr.store(out, "---needs a header---")




To set a Property


pp.setProperty('name', 'value')




To read a Property


pp.getProperty('name')




To kill a Property


pp.remove('name')




To list all current Properties


String list

for(Enumeration e = pp.keys();

e.hasMoreElements()

:{list = list + "n" + e.nextElement()

}

return list.replace('nulln', '')

Posted

Mixed this up with Todd Geist,s Expando method today. He pointed out that attaching the Expando to the FMPro class means it will only die when the application is shut SO

// fm_var == variable name

// fm_value == value to set

// fm_FileOut and fm_FileIn are paths to saved end of session variables

// and you can change the .jr to be any class of your choosing

Here's some experiments

// Set



try{

fmpro.jr."$fm_var" = fm_value

} catch (e) {com.prosc.beanshell.FMPro.metaClass.jr = new Expando()

fmpro.jr."$fm_var" = fm_value

}

if ( fmpro.jr.getProperty ( fm_var ) == fm_value){

return true

}




Read




// Read



try{

fmpro.jr."$fm_var"

} catch (e) {return false

}

fmpro.jr."$fm_var"




Save


// Save



String line = ""

writer = new OutputStreamWriter( new FileOutputStream( fm_FileOut ), "utf-8" )

writer.write(fmpro.jr.toString().replace("{","").replace("}","").replace("=",":").replace(", ", "n"))

writer.close()

return true




Load


// Load



ff = fm_FileIn

exists = (new File(ff)).exists()

if (exists){

saved = new File( fm_FileIn ).getText()

} else {

return false

}

list = saved.tokenize("n")

try{

fmpro.jr

} catch (e) {com.prosc.beanshell.FMPro.metaClass.jr = new Expando()

}

list.each {it ->

pos = it.indexOf(":")

len = it.size()

if (pos+1 == len){

end = ""

}else {

end = it[pos+1..len-1]

kk = it[0..pos-1]

fmpro.jr."$kk" = "$end"

}

}

return fmpro.jr

  • 1 year later...
  • Newbies
Posted

Hi Friends!

I used ScriptMaster and the tips from this thread (specifically system.setProperty() and system.getProperty() ) to store a serialized java hash map (I think it was) of key/value pairs, which I can then later read back, deserialize and use in a registered groovy function as a dynamic input to the function; a list I can loop over and process. Works great.

News is that this is now breaking on Windows but not on Mac, using an FM Server shared database with Windows and Mac clients.

Anyone have any insight about the internal format FM uses to store data (UTF-8, ISO-8859, ???), and why sending FM field data to a registered groovy function on Windows would behave differently than on a Mac? Specifically, when I try to manipulate the data in the groovy script on the Windows client, if it has any special chars like Asian chars or smart quotes then the groovy script can break; however the exact same script and inputs on a Mac client does just fine.

Could it be possible that FM uses, say, UTF-8 to store these chars but the ScriptMaster plugin on Windows was compiled under ISO-8859 (or vice-versa)?

Curiously,

~Darren

PS: This is a critical issue that I have to find some solution for tomorrow. I can post more specific error messages and code when I can get back to run the tests again. In the meantime I wanted to start wheels turning, in case anyone who reads this has run into this already or has any clues or suggestions on things to try.

This topic is 4617 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.