The problem is the line set TagList to TagList & TaskX. What you’re attempting to do (as I understand it) is add TaskX as a new item to the end of the list TagList. What you’re doing is concatenating a list and a record. The results are not what you’re expecting. I’m not sure that’s even defined in AppleScript.
The most common correct ways to append an item to a list in AppleScript are:
copy TaskX to the end of TagList
or
set TagList to TagList & {TaskX}
The first appends an item to the end of the list (you could also use set the end of TagList to TaskX). The second concatenates two lists by placing the item taskX into a list, and then concatenating it with TagList.
That the item you’re appending to the list is a record is irrelevant to the process of appending.
The second part of your question is more difficult, because it’s technically not possible. AppleScript’s lists don’t really care what’s inside them, and because of this you can’t request only those records with a particular value in a particular field.
What you’ll have to do is iterate through the list looking for that field; most likely creating a handler. It would likely look something like this (see Apple’s documentation About Handlers):
to findTask of taskList given id:desiredId
repeat with i from 1 to the number of items of taskList
if the id of item i of taskList is desiredId then
return item i of taskList
end if
end repeat
end findTask
This example generates a list of twenty-one records, whose names are “Item 1”, “Item 2”, “Item 3”, and so on, whose due dates are the dates beyond the current date, sequentially, and whose id is the same as the item number in the name.
set TagList to {}
repeat with i from 1 to 21
set taskName to "Item " & i
set taskDue to the (current date) + i * days
set TaskX to {name:taskName, duedate:taskDue, id:i}
copy TaskX to the end of TagList
--set TagList to TagList & {TaskX}
--set the end of TagList to TaskX
end repeat
findTask of TagList given id:3
to findTask of taskList given id:desiredId
repeat with i from 1 to the number of items of taskList
if id of item i of taskList is desiredId then
return item i of taskList
end if
end repeat
end findTask
The hardcoded call asking for the item with an id of 3 produces:
{name:"Item 3", duedate:date "Sunday, September 12, 2021 at 2:01:19 PM", id:3}
Adding get the name of the result after the findTask call produces "Item 3", which is the name of that arbitrarily-generated record.
{|name|:taskName, Duedate:taskDue, |Note|:taskNote, |id|:taskId}is a record.