How to get record.fields.Name? Not the value but the name of the record.

I can get the value of every field in the data mapper but I need the name of the field as well. Is there a way to get xml “Name” or maybe just using js to get record.fields.name?

var Body = results.loadhtml(‘Snippets/Main.html’) ;

var Count =record.fields.length;

var i =0;

var Output=;

while (i < Count)

{

Output=[Output + record.fields[i] + “,”];

i++;

}

results.html(Output);

One possibility would be to stringify the record and then extract the field names from the resulting JSON. So long as you work with the JSON as an object (not an array), the field names will be available to you through javascript. You could then pass them into a variable and use them however you need.

For more information on how to do this, you can refer to http://stackoverflow.com/questions/14386121/json-get-field-name

How do you stringify the record name? I am working with the data mapper, which is XML I believe.

The process will be very similar to what is decribed here: http://learn.objectiflune.com/en-us/pres-connect/howto/passing-record-data-to-your-frontend-web-page

The important part is the JSON``.stringify() ____ function. This will take your entire record set, values and field names alike, and output a string of JSON that looks something like this:

{“tables”: {},“fields”: {“eventName”: “Christmas”,“eventThemeName”: “We wish you a merry Christmas”,“eventCode”: 2,“eventDate”: “December’s 24th and of course 25th”,“eventStartingHour”: “18H00”,“eventEndingHour”: “When there is no one left!!!”,“eventMisc”: “”,“dateEvent”: “2016-09-14T03:48:22.000Z”,“ExtraData”: “”},“index”: 1,“id”: 0}

You can pass in the entire record: JSON``.stringify(record) or only a small portion of it JSON``.stringify(record.tables.my_table)

From here, you can see that my field names are listed in the string along with the values in the format {“FIELDNAME”: “VALUE”}. Now you’ve got the field names in a string that you can work with. Take a look through code examples linked previously to find a method that best fits the needs of your project.

Best of luck and happy coding!