Since you’re dragging and dropping out of a detail table, it’s kind of normal. The default script assumes that you’re attempting to show the next iteration from the detail table. A standard use for detail records would be something like an invoice where you’re going to be displaying a variable number of lines of an invoice. So the software works under the assumption that anything in a detail table is meant to be iterated through.
If you had 2 records in your detail table, for example, the script would not have produced an error, but still wouldn’t have given you the result you’re after. You’d have had the entry from detail 1 in the first and detail 2 in the second.
Here’s the script that produces:
results.each(function(index) {
var field, result = “”;
field = record.tables[“detail”][index].fields[“Description”];
if (field !== “”) result += field;
this.html(result);
});
Results is equal to the text you’re searching for. So this script is going to go through each result it finds. If there are 20 results, it’s looping 20 times. For each one it sets an index and then uses that index to retrieve a value from the detail table. For every instance it finds on the page, it will attempt to insert a new value from the next detail record.
Now here’s the standard script for something that is not in a detail table.
var field, result = “”;
field = record.fields[“DueDate”];
if (field !== “”) result += field;
results.html(result);
Note that it doesn’t loop through the data. That whole results.each structure is missing. It instead applies the exact same fixed field to every instance of results that it finds.
So an easier way of accomplishing what you’re attempting to do would be to modify the default script to look more like the second one.
var field, result = “”;
field = record.tables[“detail”][0].fields[“Description”];
if (field !== “”) result += field;
results.html(result);
Here we’ve removed the loop entirely. We’re just calling exactly the one field that we want and we’re displaying it on the page. It’s going to show the same value in every instance of the text selector that it finds.
This may not be the ‘right’ way for what your attempting either, however. Ultimately, you’ve got data in a detail table. Wouldn’t you need to be able to display all of the records in that detail at some point? If so, are you going to be manually placing items on the page for each one? What happens if the number of detail records becomes variable? You might need to reconsider how you’re going about the placement of this data.