I'm using Google Apps Script, whose Drive library has the following function:
setSharing(accessType, permissionType)
accessType: Access (enum)
permissionType: Permission (enum)
To allow for a good user experience, I have the following objects to match enum values to nice Strings, and vice-verca (I only show here the objects for the Access, but I have the same for the Permission):
/*** Method 1 ***/
var ACCESS_STR = {};
var ACCESS_ID = {};
ACCESS_STR[ DriveApp.Access.ANYONE ] = "Any.";
ACCESS_STR[ DriveApp.Access.ANYONE_WITH_LINK ] = "Any. w/link";
ACCESS_STR[ DriveApp.Access.DOMAIN ] = "Domain";
...
ACCESS_ID[ "Any." ] = DriveApp.Access.ANYONE;
ACCESS_ID[ "Any. w/link" ] = DriveApp.Access.ANYONE_WITH_LINK;
ACCESS_ID[ "Domain" ] = DriveApp.Access.DOMAIN;
...
What i'd like to do is to programmatically build the second object since all the needed information is already contained in the first one; this is what I do: /* Method 1 */ var ACCESS_STR = {}; var ACCESS_ID = {}; ACCESS_STR[ DriveApp.Access.ANYONE ] = "Any."; ACCESS_STR[ DriveApp.Access.ANYONE_WITH_LINK ] = "Any. w/link"; ACCESS_STR[ DriveApp.Access.DOMAIN ] = "Domain"; ... for( var a in ACCESS_STR ) { ACCESS_ID[ ACCESS_STR[a] ] = a; }
Now, if I call setSharing( ACCESS_ID["Any."], PERMISSION_ID["Edit"]), then
- with method 1, it works
- with method 2, I get a
setSharing(string,string) method unknownerror.
Why is that, and how can I cast back the strings to the enum type?
