Arrays: keeping a String a String

In a table records have a field (fd_Org_ID) used to enforce a hierarchical order (it is a table containing information about an organization’s structure). The data is something like “01.00.00.00.01.00” where each couple of digits represent one level of the structure.

To manipulate the data and build organizational charts I need to create arrays of objects identified by their respective Org_ID such as

arrayOrg[fd_Org_ID] = {"Loc" : fd_Country, "Floor" : fd_Floor };
```The problem is that the string value fd_Org_ID is recognized by JavaScript as an array and not as a string. I tried to add an empty string ```
arrayOrg[""+fd_Org_ID+""]
``` with no success. I then removed all the dots, and created a method removing and restoring the dots back and forth when the original value is needed.

Is there a way to avoid this? Thanks for any help.

What if you try this?

arrayOrg[String(fd_Org_ID)]

No, it doesn’t work. It is still seen as an array. I forgot to mention that I tried all sorts of String, toString a.s.o. without any success. Thank you, anyway

Hi Rioba,

I did a test it all works fine for me:

var arrayOrg = new Array(),
	fd_Org_ID = "01.00.00.00.01.00",
	fd_Country = "testvalue1",
	fd_Floor = "testvalue2";

arrayOrg[fd_Org_ID] = {"Loc" : fd_Country, "Floor" : fd_Floor };
application.output(arrayOrg[fd_Org_ID]["Loc"]);

This fd_Org_ID is a table column? What actual datatype is it in the backend database (and how does Servoy interpret it)?
Also what version of Servoy are you using here?

Hi Robert,

thank you so much, you are right as usual. The fact is that checking my code in the debug window this was the result with the dots in the fd_Org_ID string

while using the string without any dot the result in the debug pane was

Looking at the debug window I thought that the values could not be retrieved using the literal description. I see that this is not true, and if I ask for arrayOrg[fd_Org_ID][“Loc”] I get the correct result (“France”). Still, I don’t understand these different behaviors in the debugging view.

Thank you very much (although now I have to rewrite all my code using again the strings containing the dots :evil:)