on should expand item theObject outline item outlineItem

Hi folks
this has kept me working a long time now and I get nowhere.

When I click on a line in an outline view, I need to know the contents of the data cell that was clicked what has been clicked.
If I click on the line itself I get a clicked event and from that I can get what I need.

set outlineItem to clicked data item of ourView
set itemName to contents of data cell “name” of outlineItem

gives me what I need.

if I click on a triangle to expand the parent to show the children instead, I don’t get the clicked event but, when disclosing children, I get a “should expand item” event.
Great I thought, I can get the name of item clicked there.
But no I cannot. I cannot log anything at all about outlineItem.
All I get is an error “Can’t make data item id 74 of data source id 69 into type Unicode text. (-1700)”
no matter what I try.
Where am I going wrong?

Here is the code


on should expand item theObject outline item outlineItem
log name of theObject – works ok and I get outline
log name of outlineItem – does not work
log contents of data cell “name” of outlineItem – does not work either
end should expand item

Thanks for your help.