Error updated custom columns

Hello all,

I am creating a script to add some custom columns. I am looking up and address using googles maps API.
The columns are updating correctly and all the columns display as expected.

However when I show more than one columns, the On function is called multiple times. For each extra call and error is displayed when the method tries to update the columns.
Error: "Subscript out of range (0x800a0009)"

GoogleMapsApi.js.txt (15.4 KB)

Not sure why the On method is called multiple times, and why it errors on the extra calls.

In multicol mode, scriptColData gives you a Map of columns that Opus is asking for. You're meant to loop through that Map, check each column's name, and fill it in as appropriate. (Or check if the Map contains a named column, and fill it in if it is there.)

You shouldn't assuming any particular columns will always be in the Map inside the OnScriptColumn function, as it will depend on which columns are displayed.

You probably just need to check if the name/key you want to set the value for exists in the map before trying to set it.

Opus may also call the script's OnScriptColumn function(s) multiple times if only some of the columns were filled in by previous calls and it still needs data for others.

1 Like

Ah ok, that makes sense. Cheers mate.

I've realised one of my own scripts had the same problem, and got away with it because it's usually true that all the columns are in the map, but not always.

Least its not just me ;).

Did you code up a fix for it? I have not gotten back to that one yet. I only needed the Suburb and it does not error for one column.

Might be related to this?: Multicolumn issue, getting unexpected exceptions

From my point of view, there is something working differently now than before DO12.
I remember that you were able to fill in all the multicol columns whenever a multicol function was called in DO11.

I also remember a discussion where I tried to make you understand that there are even sinclecol columns in the column map, when a multicol function is called and that this is unexpected. So there were even more columns in there at that time. And now not even all the multicol columns can be set - only the ones currently in data.columns?

This probably breaks existing scripts and I got the feeling it broke some of mine (ScriptWizard columns certainly do not work as expected anymore, but I'm not clear yet whether this is related to the bug Jon has fixed in the thread given above).
All singcol column values show up and disappear again depending on whether there are multicol columns in use at the same time and whether these multicols show up before or after the singlecol columns in the filedisplay.

I may cite the documentation, there's no hint to missing columns and a required/prior check to see if the ones to be set are in data.columns (as said, this map was always full and complete iirc):

If the ScriptColumn.multicol value is set to True when the column is added, then this property provides a Map that lets you return the values of one or more columns at once.

You may want to use this method if your script returns multiple columns that all share common calculations (e.g. reading the contents of a folder). That way, you can avoid repeating potentially time consuming operations when you're called for the second and subsequent columns.

The Map contains one member element for each of your columns. Each member element has group, sort, type and value properties which are equivalent to the ones described below.

For example, you might set the value of a column called MyColumn like this:

scriptColData.columns("MyColumn").value = "My Column Value";

I did not test what the current situation really is, if data.column really misses some multicol columns sometimes now with DO12. Hard to tell currently with the other issues mixing in.
It would be nice if there would be a clear statement on how this is meant to work (I also remember a recent discussion with Jon where he remembered some things differently and then came to the conclusion that it's rather like I meant it should be).

Confusion all over! Cya! o)

This fix of yours Leo, for the column script right here: Newest File column
It probably fixes something which needs fixing in all other column scripts if it's not fixed within the DO code itself. More guessing than knowing, but to me it feels kinda strange as I dealt with these excepetions as well. Again, not sure if Jon already fixed this specific thing, which would render your script fix unecessary in theory.

Jon said his changes for your bug may also have removed the need for checking the column map, but we're not completely sure at the moment.

I've never reproduced the problem myself, as in normal use Opus does ask for all the columns, but the way to avoid it in the script is quick and easy and probably makes sense anyway. Best not to assume a map that came from outside the script contains anything without checking first. It was just something I didn't think to do when writing the original script. (I was probably in the mindset of C++ maps where the same code would insert the missing element if it wasn't there already, so you don't generally need to check.)

If we can work out quick & reliable way to make the map not contain all the columns, we should be able to work out why it happens sometimes, but so far we haven't found a way to do that.