Jump to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

register scriptmaster fonction failed

Featured Replies

Hi

I set a variable with


RegisterGroovy( "List_All_Files_In_Directory ( path )" ;

"def result = new StringBuffer();

def dir = new File(path);

count = 0;

listFiles( dir, result );

result.toString().trim();

void listFiles( File directory, StringBuffer buff ) {

for (eachFile in directory.listFiles() ) {

  if (eachFile.getName().startsWith(\".\")) continue;

  buff.append(\"\n\" + eachFile.getPath());

  if( eachFile.isDirectory() ) {

   buff.append( File.separator );

  }

  count++;

}

} ")

and get error

org.codehaus.groovy.control.MultipleCompilationerrorsException: startup failed:

Script1.groovy: 1: unexpected token: count @ line 1, column 389.

pend( File.separator ); } count++;

^

1 error

  • Author

perhaps it is the n character wich failed

I've tried "n" or "n" without success

Did you test the code as a ScriptMaster module first to confirm the code will compile?

  • Author

Yes i do

it runs

  • Author

if i put this code in a field and put into the groovy quote (field), it works.

I think it is probably the character, but i don't

so now i put :

RegisterGroovy( "List_All_Files_In_Directory ( path )" ;

quote ("def result = new StringBuffer();

def dir = new File(path);

count = 0;

listFiles( dir, result );

result.toString().trim();

void listFiles( File directory, StringBuffer buff ) {

for (eachFile in directory.listFiles() ) {

if (eachFile.getName().startsWith(".")) continue;

buff.append("n" + eachFile.getPath());

if( eachFile.isDirectory() ) {

buff.append( File.separator );

}

count++;

}

}")

)

and it works !

  • Author

in fact it records well, but the function does not work

error :

def result = new StringBuffer(); def dir = new File(path); count = 0; listFiles( dir, result ); result.toString().trim(); void listFiles( File directory, StringBuffer buff ) { for (eachFile in directory.listFiles() ) { if (eachFile.getName().startsWith(".")) continue; buff.append("

" + eachFile.getPath()); if( eachFile.isDirectory() ) { buff.append( File.separator ); } count++; } }

  • Author

now it seems to be right with :

RegisterGroovy( "List_All_Files_In_Directory ( path )" ; "def result = new StringBuffer();¶def dir = new File(path);¶count = 0;¶listFiles( dir, result );¶result.toString().trim();¶¶void listFiles( File directory, StringBuffer buff ) {¶ for (eachFile in directory.listFiles() ) {¶ if (eachFile.getName().startsWith(".")) continue;¶ buff.append("n" + eachFile.getPath());¶ if( eachFile.isDirectory() ) {¶ buff.append( File.separator );¶ }¶ count++;¶ }¶}")
  • Author

it works in a calculating field, bu the dataviewer don't like this function

This is a great example where being more Groovy in the code will help troubleshooting:

Using


if (eachFile.getName().startsWith('.'))

in the code will show the same in the RegisterGroovy code rather than the escaped version, making it much easier to read.

  • Author

thanks John !

Create an account or sign in to comment

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.