Expand my Community achievements bar.

How to access data using Javascript?.

Avatar

Level 3

Hi, I've been trying to read a dat field from an xml source, without success so far.

Actually, I did read data, but only data that is not repeated, I mean, data that is not inside something like:

<item>

   <values>

   ...

<item>

<item>

  <values>

  ...

<item>

.

.

.

<item>

  <values>

  ...

<item>

Using $record.path.field.value, I could retrieve the data I was looking for, but I now have to check something while I fill a table, and for some reason I just can't "place the cursor" where it should be.

I've also tried using the [*] keyword, but it didn't do anything.

What I'd need to do is very simple, I have a column (type), that I need to read for every row I fill in a table, if the field value is "A" then the amount value that comes from the XML must be placed into a particular column, if it is "B", then in another column. (type is "credit" or "debit", and amount goes into credit or debit column, according to type data in the xml).

Thanks in advance!.

1 Reply

Avatar

Level 10

Hi,

try something along the lines of;

var dataItems = $record.resolveNodes("item[*]");

for (var i = 0; i < dataItems.length; i++)

{

    var dataItem = dataItems.item(i);

    var dataValues = dataItem.resolveNodes("values[*]");

    for (var j = 0; j < dataValues.length; j++)

    {

        var dataValue = dataValues.item(j);

        // do something with a value element

    }

}

If the values element in your sample had a type element then you could reference it at the "do something..." point with "dataValue.type.value".

Regards

Bruce