What error are you getting?
Perhaps "grid" isn't a global variable, at a guess. And can't be referenced by the object running the code.
And if there's several instance of that object, it might be best to store the "id" rather than the "object_index".