I have a couple of functions that I would like to be available to multiple sheets, so I took them from the sheet I am working on and put them in a .js file, then added the file by going to: Sheet -> Document Setup -> Script Configuration
However, now the sheet throws a runtime error when testing. Is there any other specific steps that must be taken either in the external script file or the sheet itself?
Comments
This is the code I put in the external file. All I did was to put the functions in a text file named DiceRoller.js
This is an example of the calling code (the function call works when the above is in the script section of the sheet, but not when it is put in the external file.)
Thanks for looking at this.
I've found that they can be caused by fields being set to read only, and once by a field that had been accidentally pasted (that happens if you try to paste into the Script tab) behind something else.
I figure, check the status of your fields, see if something is read only or not.
As a test I took a working character design and added a text edit box that is completely editable (i.e. not read only, not hidden, not a number). I set the fieldname as test123. For the source I included a simple function call called magicBean();
In an external testFile.js file I create this function and define it as such:
function magicBean(){
return "I am a bean";
}
I go into the sheet -> Document Setup -> Script Configuration and add my testFile.js into the external scripts area.
Now I got to test this sheet in the viewer and I get a script error. The scripting error is a result of the field update to the field named test123 and the source call magicBean();
Obviously this field is not seeing my external javascript file.
To show that this isn't a result of the external script not being correct, I then copy the function magicBean() from the external javascript file and place it into the built in script editor. I make sure to right click and select paste rather than hitting ctrl-v which will make a copy of the field I had selected on the WYSIWYG editor. With the magic bean function in place I not rerun my character design and voila, it starts up with no error. As expect the field named test123 is being displayed as "I am a bean".
So I can only conclude that either there is a special way external scripts are called by the character designer or that external .js files aren't supported despite the documentation saying:
"You can also access a field directly in a javascript function, like:
function AdjustHits()
{
Hits.Text = Strength.Value + Constitution.Value;
}
External JavaScript files can be used to store oft used functions. See the document setup
window for where you set that up."
I have tested this on both windows 7 and windows 8 and it seems to be the case for both. If anyone wouldn't mind testing this on other OS I would be curious if it's an OS issue or an actual bug with the application.