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’) ;
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.
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.